-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.jsx
229 lines (221 loc) · 7.26 KB
/
main.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import React from 'react';
import { Accounts, STATES } from 'meteor/std:accounts-ui';
/**
* Form.propTypes = {
* fields: React.PropTypes.object.isRequired,
* buttons: React.PropTypes.object.isRequired,
* error: React.PropTypes.string,
* ready: React.PropTypes.bool
* };
*/
class Form extends Accounts.ui.Form {
render() {
const {
hasPasswordService,
oauthServices,
fields,
buttons,
error,
message,
ready = true,
className,
formState
} = this.props;
return (
<form ref={(ref) => this.form = ref} className={[ "accounts", className ].join(' ')}>
{Object.keys(fields).length > 0 ? (
<Accounts.ui.Fields fields={ fields } />
) : null }
{ buttons['switchToPasswordReset'] ? (
<fieldset className="form-group">
<Accounts.ui.Button className="btn-sm" {...buttons['switchToPasswordReset']} />
</fieldset>
) : null }
<fieldset className="form-group">
{_.values(_.omit(buttons, 'switchToPasswordReset', 'switchToSignIn',
'switchToSignUp', 'switchToChangePassword', 'switchToSignOut', 'signOut')).map((button, i) =>
<Accounts.ui.Button {...button} key={i} />
)}
{ buttons['signOut'] ? (
<Accounts.ui.Button {...buttons['signOut']} type="submit" />
) : null }
{ buttons['switchToSignIn'] ? (
<Accounts.ui.Button {...buttons['switchToSignIn']} type="button" className="ui button" />
) : null }
{ buttons['switchToSignUp'] ? (
<Accounts.ui.Button {...buttons['switchToSignUp']} type="button" className="ui button" />
) : null }
{ buttons['switchToChangePassword'] ? (
<Accounts.ui.Button {...buttons['switchToChangePassword']} type="button" className="ui button" />
) : null }
{ buttons['switchToSignOut'] ? (
<Accounts.ui.Button {...buttons['switchToSignOut']} type="button" className="ui button" />
) : null }
</fieldset>
<fieldset>
{ formState == STATES.SIGN_IN || formState == STATES.SIGN_UP ? (
<Accounts.ui.PasswordOrService oauthServices={ oauthServices } />
) : null }
{ formState == STATES.SIGN_IN || formState == STATES.SIGN_UP ? (
<Accounts.ui.SocialButtons oauthServices={ oauthServices } />
) : null }
</fieldset>
<fieldset>
<Accounts.ui.FormMessage className="alert alert-danger m-t-1 m-b-0" role="alert"
style={{display: 'block'}} {...message} />
</fieldset>
</form>
);
}
}
class Buttons extends Accounts.ui.Buttons {
}
class Button extends Accounts.ui.Button {
render() {
const {
label,
href = null,
type,
disabled = false,
onClick,
className,
icon
} = this.props;
return type == 'link' ? (
<a href={ href }
style={{cursor: 'pointer'}}
className={ className }
onClick={ onClick }>
{ icon ? (<i className={["fa", icon].join(' ')} />) : null }{ icon ? ' | ' : ''}{ label }
</a>
) : (
<button className={ [
'btn',
type == 'submit' ? 'btn-primary' : '',
disabled ? 'disabled' : '',
className
].join(' ') }
type={ type }
disabled={ disabled }
onClick={ onClick }>
{ icon ? (<i className={["fa", icon].join(' ')} />) : null }{ icon ? ' | ' : ''}{ label }
</button>
);
}
}
class Fields extends Accounts.ui.Fields {
render() {
let { fields = {}, className = "" } = this.props;
return (
<fieldset className={ [className].join(' ') }>
{Object.keys(fields).map((id, i) =>
<Accounts.ui.Field {...fields[id]} key={i} />
)}
</fieldset>
);
}
}
class Field extends Accounts.ui.Field {
render() {
const {
id,
hint,
label,
type = 'text',
onChange,
required = false,
className,
defaultValue = ""
} = this.props;
const { mount = true } = this.state;
return mount ? (
<div className={["form-group", required ? "required" : ""].join(' ')}>
<label htmlFor={ id } className="form-control-label control-label">{ label }</label>
<input id="password" className="form-control" name="password" style={{display: 'none'}} />
<input id={ id }
className="form-control"
name={ id }
type={ type }
ref={ (ref) => this.input = ref }
autoCapitalize={ type == 'email' ? 'none' : false }
autoCorrect="off"
onChange={ onChange }
placeholder={ hint }
defaultValue={ defaultValue }
required={required ? "required" : ""} />
</div>
) : null;
}
}
export class PasswordOrService extends Accounts.ui.PasswordOrService {
render() {
let { className, style = {} } = this.props;
let { hasPasswordService, services } = this.state;
labels = services;
if (services.length > 2) {
labels = [];
}
if (hasPasswordService && services.length > 0) {
return (
<div className="or-sep">
<p style={ style } className={ className }>
{ `${T9n.get('orUse')} ${ labels.join(' / ') }` }
</p>
</div>
);
}
return null;
}
}
class SocialButtons extends Accounts.ui.SocialButtons {
render() {
let { oauthServices = {}, className = "social-buttons" } = this.props;
if (Object.keys(oauthServices).length > 0) {
return (
<div className={[ className ].join(' ')}>
{Object.keys(oauthServices).map((id, i) => {
var mapObj = {
google: "google-plus",
"meteor-developer": ""
};
let serviceClass = id.replace(/google|meteor\-developer/gi, (matched) => {
return mapObj[matched];
});
return (
<Accounts.ui.Button key={i} {...oauthServices[id]}
className={serviceClass.length > 0 ? `btn-social btn-${serviceClass}` : ''}
icon={serviceClass.length > 0 ? `fa-${serviceClass}` : ''} />
);
})}
</div>
);
} else {
return null;
}
}
}
class FormMessage extends Accounts.ui.FormMessage {
render() {
let { message, type, role, className = "message", style = {} } = this.props;
return message ? (
<div style={ style }
className={[ className, type ].join(' ')}
role={role}>{ message }</div>
) : null;
}
}
// Notice! Accounts.ui.LoginForm manages all state logic at the moment, so avoid
// overwriting this one, but have a look at it and learn how it works. And pull
// requests altering how that works are welcome.
// Alter provided default unstyled UI.
Accounts.ui.Form = Form;
Accounts.ui.Buttons = Buttons;
Accounts.ui.Button = Button;
Accounts.ui.Fields = Fields;
Accounts.ui.Field = Field;
Accounts.ui.PasswordOrService = PasswordOrService;
Accounts.ui.SocialButtons = SocialButtons;
Accounts.ui.FormMessage = FormMessage;
// Export the themed version.
export { Accounts, STATES };
export default Accounts;