]>
Commit | Line | Data |
---|---|---|
1de09faf | 1 | DoodleComponent subclass: UserAccountView [ |
2 | renderContentOn: html [ | |
3 | | user | | |
4 | user := Seaside.WACurrentSession value user. | |
5 | ||
6 | html heading level: 1; | |
7 | with: [ | |
8 | html render: 'Welcome back '. | |
9 | html render: user username. | |
10 | ]. | |
11 | html render: 'Your status is: '. | |
12 | html render: user rank. | |
13 | html break. | |
14 | html render: 'Your tokens: '. | |
15 | user polls do: [ :aPoll | | |
16 | html render: aPoll. | |
17 | html render: ', '. | |
18 | ] | |
19 | ] | |
20 | ] | |
21 | ||
22 | DoodleComponent subclass: NewUserView [ | |
23 | | user pw1 pw2 error | | |
24 | ||
25 | initialize [ | |
26 | super initialize. | |
27 | user := User new. | |
28 | ] | |
29 | ||
30 | save [ | |
31 | | uaView otheruser | | |
32 | (pw1 = pw2) ifTrue: [ | |
33 | otheruser := User find: [ :each | each username = user username ]. | |
34 | ||
35 | otheruser ifNil: [ | |
36 | user password: pw1. | |
37 | user save. | |
38 | uaView := UserAccountView new. | |
39 | Seaside.WACurrentSession value user: user. | |
40 | self call: uaView | |
41 | ] ifNotNil: [ | |
42 | error := 'User already exists'. | |
43 | ] | |
44 | ] | |
45 | ] | |
46 | ||
47 | renderContentOn: html [ | |
48 | html heading level: 1; | |
49 | with: 'Create an Account'. | |
50 | error ifNotNil: [ | |
51 | html paragraph class: 'poll-error'; | |
52 | with: error. | |
53 | ]. | |
54 | html form class: 'pure-form pure-form-aligned'; | |
55 | with: [ | |
56 | html div class: 'pure-control-group'; | |
57 | with: [ | |
58 | html label for: 'username'; | |
59 | with: 'Username'. | |
60 | html textInput callback: [ :value | user username: value ]; | |
61 | value: (user username); | |
62 | id: 'username'. | |
63 | ]. | |
64 | html div class: 'pure-control-group'; | |
65 | with: [ | |
66 | html label for: 'pw1'; | |
67 | with: 'Password'. | |
68 | html passwordInput callback: [ :value | pw1 := value ]; | |
69 | id: 'pw1'. | |
70 | ]. | |
71 | html div class: 'pure-control-group'; | |
72 | with: [ | |
73 | html label for: 'pw2'; | |
74 | with: 'Password (repeat)'. | |
75 | html passwordInput callback: [ :value | pw2 := value ]; | |
76 | id: 'pw2'. | |
77 | ]. | |
78 | ||
79 | html div class: 'pure-controls'; | |
80 | with: [ | |
81 | html submitButton callback: [ self save ]; | |
82 | value: 'Create'; | |
83 | class: 'pure-button pure-button-primary'. | |
84 | ] | |
85 | ] | |
86 | ] | |
87 | ] | |
88 | ||
89 | DoodleComponent subclass: LoginUserView [ | |
90 | | username password error | | |
91 | ||
92 | login [ | |
93 | | user | | |
94 | ||
95 | user := User find: [ :obj | obj username = username ]. | |
96 | user ifNotNil: [ | |
97 | (user password = password) ifTrue: [ | |
98 | Seaside.WACurrentSession value user: user. | |
99 | self call: UserAccountView new. | |
100 | ] ifFalse: [ | |
101 | error := 'Username / Password does not exist'. | |
102 | ] | |
103 | ] ifNil: [ | |
104 | error := 'Username / Password does not exist'. | |
105 | ] | |
106 | ] | |
107 | ||
108 | renderContentOn: html [ | |
109 | html heading level: 1; | |
110 | with: 'Login'. | |
111 | error ifNotNil: [ | |
112 | html paragraph class: 'poll-error'; | |
113 | with: error. | |
114 | ]. | |
115 | html form class: 'pure-form'; | |
116 | with: [ | |
117 | html textInput callback: [ :value | username := value ]; | |
118 | attributeAt: 'placeholder' put: 'Username'. | |
119 | html passwordInput callback: [ :value | password := value ]; | |
120 | attributeAt: 'placeholder' put: 'Password'. | |
121 | html break. | |
122 | html submitButton callback: [ self login ]; | |
123 | value: 'Login'; | |
124 | class: 'pure-button pure-button-primary' | |
125 | ] | |
126 | ] | |
127 | ] |