comparison src/nabble/view/web/user/UserEditorNamespace.java @ 0:7ecd1a4ef557

add content
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 21 Mar 2019 19:15:52 -0600
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:7ecd1a4ef557
1 package nabble.view.web.user;
2
3 import nabble.model.Message;
4 import nabble.model.ModelException;
5 import nabble.model.User;
6 import nabble.naml.compiler.Command;
7 import nabble.naml.compiler.CommandSpec;
8 import nabble.naml.compiler.IPrintWriter;
9 import nabble.naml.compiler.Interpreter;
10 import nabble.naml.compiler.Namespace;
11 import nabble.naml.namespaces.TemplateException;
12 import nabble.view.lib.Permissions;
13 import nabble.view.web.template.ServletNamespace;
14
15
16 @Namespace (
17 name = "user_editor",
18 global = true
19 )
20 public final class UserEditorNamespace {
21 private final User user;
22
23 public UserEditorNamespace(User user) {
24 this.user = user;
25 }
26
27 public static final CommandSpec save_user = CommandSpec.NO_OUTPUT;
28
29 @Command public void save_user(IPrintWriter out,Interpreter interp) {
30 user.update();
31 }
32
33 public static final CommandSpec add_to_group = new CommandSpec.Builder()
34 .dotParameter("group")
35 .build()
36 ;
37
38 @Command public void add_to_group(IPrintWriter out,Interpreter interp)
39 throws TemplateException
40 {
41 String group = interp.getArgString("group");
42 Permissions.addToGroup(user, group);
43 }
44
45 public static final CommandSpec remove_from_group = new CommandSpec.Builder()
46 .dotParameter("group")
47 .build()
48 ;
49
50 @Command public void remove_from_group(IPrintWriter out,Interpreter interp)
51 throws TemplateException
52 {
53 String group = interp.getArgString("group");
54 Permissions.removeFromGroup(user, group);
55 }
56
57 public static final CommandSpec set_signature = CommandSpec.NO_OUTPUT()
58 .parameters("signature","is_html")
59 .requiredInStack(ServletNamespace.class)
60 .build()
61 ;
62
63 @Command public void set_signature(IPrintWriter out,Interpreter interp)
64 throws ModelException
65 {
66 String signature = interp.getArgString("signature");
67 boolean isHtml = interp.getArgAsBoolean("is_html", false);
68 Message.Format fmt = isHtml? Message.Format.HTML : Message.Format.TEXT;
69 ServletNamespace servletNs = interp.getFromStack(ServletNamespace.class);
70 user.setSignature(signature, fmt);
71 }
72
73 public static final CommandSpec set_name = CommandSpec.NO_OUTPUT()
74 .parameters("name")
75 .build()
76 ;
77
78 @Command public void set_name(IPrintWriter out,Interpreter interp)
79 throws ModelException
80 {
81 String name = interp.getArgString("name");
82 user.setName(name);
83 }
84
85 public static final CommandSpec set_password = CommandSpec.NO_OUTPUT()
86 .parameters("password1", "password2")
87 .build()
88 ;
89
90 @Command public void set_password(IPrintWriter out,Interpreter interp)
91 throws TemplateException
92 {
93 String password1 = interp.getArgString("password1");
94 String password2 = interp.getArgString("password2");
95 if (password1.trim().isEmpty() && password2.trim().isEmpty())
96 return; // skip change
97 if (password1.equals(password2)) {
98 user.setPassword(password1);
99 } else
100 throw ModelException.newInstance("passwords_dont_match");
101 }
102
103 }