1 package net.sourceforge.blogentis.modules.actions;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import net.sourceforge.blogentis.turbine.BlogParameterParser;
26
27 import org.apache.turbine.modules.actions.VelocitySecureAction;
28 import org.apache.turbine.om.security.User;
29 import org.apache.turbine.services.security.TurbineSecurity;
30 import org.apache.turbine.util.RunData;
31 import org.apache.velocity.context.Context;
32
33 /***
34 * @author abas
35 *
36 * To change the template for this generated type comment go to
37 * Window>Preferences>Java>Code Generation>Code and Comments
38 */
39 public class UserMod extends VelocitySecureAction {
40 private User getUser(RunData data) {
41 BlogParameterParser pp = (BlogParameterParser)data.getParameters();
42 String userName = pp.getString("user", data.getUser().getName());
43 if (userName == null)
44 return null;
45 if (data.getUser().getName().equals(userName))
46 return data.getUser();
47 try {
48 return TurbineSecurity.getUser(userName);
49 } catch (Exception ignored) {
50 return null;
51 }
52 }
53
54 public void doPreferences(RunData data, Context context)
55 throws Exception {
56 User u = getUser(data);
57 BlogParameterParser pp = (BlogParameterParser)data.getParameters();
58
59 u.setPerm("convertBreaks", pp.getBooleanObject("convertBreaks",
60 Boolean.FALSE));
61 u.setPerm("tidyHTML", pp.getBooleanObject("tidyHTML", Boolean.FALSE));
62 u.setPerm("editboxHeight", new Integer(pp.getInt("editboxHeight", 20)));
63
64 TurbineSecurity.saveUser(u);
65 }
66
67 public void doPassword(RunData data, Context context)
68 throws Exception {
69 User u = getUser(data);
70 BlogParameterParser pp = (BlogParameterParser)data.getParameters();
71 String pw1 = pp.getString("password1", "-");
72 String pw2 = pp.getString("password2", "+");
73 if (!pw1.equals(pw2)) {
74 data.setMessage("Passwords do not match!");
75 return;
76 }
77 u.setPassword(pw2);
78 TurbineSecurity.saveUser(u);
79 }
80
81 public void doInfo(RunData data, Context context)
82 throws Exception {
83 User u = getUser(data);
84 BlogParameterParser pp = (BlogParameterParser)data.getParameters();
85 u.setEmail(pp.getString("mailAddress", u.getEmail()));
86 u.setFirstName(pp.getString("firstName", u.getFirstName()));
87 u.setLastName(pp.getString("lastName", u.getLastName()));
88 TurbineSecurity.saveUser(u);
89 }
90
91 public void doPerform(RunData data, Context context)
92 throws Exception {
93 data.setMessage("Requested action not found.");
94 }
95
96 protected boolean isAuthorized(RunData data)
97 throws Exception {
98 if (!data.getUser().hasLoggedIn())
99 return false;
100 User u = getUser(data);
101 if (u == null)
102 return false;
103 if (data.getUser().getName().equals(u.getName()))
104 return true;
105 return data.getACL().hasPermission("admin_site");
106 }
107 }