source: trunk/src/org/expeditee/auth/tags/AuthenticationTag.java@ 1363

Last change on this file since 1363 was 1363, checked in by bln4, 5 years ago

It is now possible to complete the process of recovering access to a Expeditee account. Further work, in the form of frames in the authentication frameset, are to follow.
A refactoring/tidy up has also been completed.

File size: 2.3 KB
Line 
1package org.expeditee.auth.tags;
2
3import java.util.Collection;
4import java.util.HashMap;
5import java.util.Map;
6import java.util.Optional;
7
8import org.expeditee.items.Text;
9
10public enum AuthenticationTag {
11 Username ("txtUsername", System.getProperty("user.name")),
12 Password ("txtPassword", System.getProperty("user.password")),
13 PasswordAgain ("txtPasswordAgain", System.getProperty("user.password.again")),
14 NewPassword ("txtNewPassword", System.getProperty("user.new.password")),
15 NewPasswordAgain ("txtNewPasswordAgain", System.getProperty("user.new.password.again")),
16 Email ("txtEmail", System.getProperty("user.email")),
17 EmailAgain ("txtEmailAgain", System.getProperty("user.email.again")),
18 ColleagueOne ("txtColleagueOne", System.getProperty("user.colleague.one")),
19 ColleagueTwo ("txtColleagueTwo", System.getProperty("user.colleague.two")),
20 Frameset ("txtFrameset", System.getProperty("user.toshare.frameset")),
21 IntergalacticNumber ("txtIntergalacticNumber", System.getProperty("user.intergalacticnumber")),
22 PasswordSliceOne ("txtPasswordPieceOne", System.getProperty("user.password.piece.one")),
23 PasswordSliceTwo ("txtPasswordPieceTwo", System.getProperty("user.password.piece.two"));
24
25 public String val;
26 public String def;
27
28 private AuthenticationTag(String tag, String def) {
29 this.val = tag;
30 this.def = def;
31 }
32
33 public static Optional<Map<AuthenticationTag, String>> fetchUserData(Collection<Text> from, boolean useDefaults, AuthenticationTag... tags) {
34 final Map<AuthenticationTag, String> fetchedData = new HashMap<AuthenticationTag, String>();
35
36 for (AuthenticationTag tag: tags) {
37 for (Text canditate: from) {
38 // use the canditate if it exists
39 if (canditate.hasData(tag.val)) {
40 if (tag.val.equals("txtUsername")) {
41 fetchedData.put(tag, canditate.getText().toLowerCase());
42 } else {
43 fetchedData.put(tag, canditate.getText());
44 }
45 break;
46 }
47 // otherwise try use the default
48 String property = tag.def;
49 if (property != null && !property.isEmpty()) {
50 fetchedData.put(tag, useDefaults ? property : null);
51 }
52 }
53 }
54
55 if (fetchedData.entrySet().size() == tags.length) {
56 return Optional.of(fetchedData);
57 } else {
58 return Optional.empty();
59 }
60 }
61}
Note: See TracBrowser for help on using the repository browser.