EnterLayout.js
4.88 KB
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
import _ from 'lodash';
import { Meteor } from 'meteor/meteor';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
import { Bert } from 'meteor/themeteorchef:bert';
import React from 'react';
import { Container, Row, Col } from 'reactstrap';
import { Link } from 'react-router';
import { If, Case } from '/imports/client/components/Logic';
import { LoginPane } from '/imports/client/views/org/enter/LoginPane';
import { ForgotPane } from '/imports/client/views/org/enter/ForgotPane';
import { ResetPane } from '/imports/client/views/org/enter/ResetPane';
import Validation from '/imports/validation/validationMethods';
// const signupSchemaValidator = new SimpleSchema({
// email: { type: String, regEx: SimpleSchema.RegEx.Email},
// firstName: { type: String, },
// lastName: { type: String, },
// password: { type: String, min: 6},
// }).validator();
let validation = new Validation();
export class EnterLayout extends React.Component {
constructor(props) {
super(props);
this.state = {
email: '',
password: '',
firstName: '',
lastName: '',
orgName: '',
loading: false,
error: '',
message: '',
};
};
componentWillReceiveProps(nextProps) {
console.log(this.props.pane);
console.log("this.props.pane");
if(this.props.pane !== nextProps.pane) {
this.onClearState();
}
};
onClearState(loading) {
this.setState({
loading: loading || false,
error: '',
message: '',
});
};
onUpdate(key, value) {
this.setState({[key]: value});
};
onForgot(e) {
e.preventDefault();
this.onClearState(true);
Accounts.forgotPassword({email: this.state.email || '...'}, (error) => {
this.onClearState();
if(error) {
this.setState({error: 'An error occured.'});
} else {
this.setState({message: 'Reset email has been sent. Check your inbox.'});
}
});
};
onReset(e) {
e.preventDefault();
this.onClearState(true);
if(!validation.passwordValidation(this.state.password)){
Bert.alert('Password must be a minimum of 6 characters in length.', 'danger');
this.onClearState();
return false;
}else if(!validation.noQwertysAllowed(this.state.password)){
Bert.alert('No qwertys allowed!', 'danger');
this.onClearState();
return false;
} else{
Accounts.resetPassword(
this.props.location.query.token,
this.state.password,
(error) => {
this.onClearState();
if(error) {
this.setState({error: 'An error occured.'});
}
}
);
}
};
onLogin(e) {
e.preventDefault();
this.onClearState(true);
if(this.state.email.trim() == '' || !validation.validateEmail(this.state.email)){
this.onClearState();
Bert.alert('Please enter a valid email address!', 'danger');
return false;
}
if(this.state.password.trim() == ''){
Bert.alert('Please enter your password!', 'danger');
this.onClearState();
return false;
}
Meteor.loginWithPassword(
this.state.email,
this.state.password,
(e, r) => {
this.onClearState();
if(e) {
this.setState({error: 'Wrong email or password.'})
}
}
);
};
render() {
return (
<div className = "enterLayout__content--bg">
<Container>
<Row>
<Case
switch = {this.props.pane}
case0 = "forgot"
then0 = {() => (
<ForgotPane
data = {this.state}
location = {this.props.location}
onUpdate = {(...a) => this.onUpdate(...a)}
onForgot = {(...a) => this.onForgot(...a)}
/>
)}
case1 = "reset"
then1 = {() => (
<ResetPane
data = {this.state}
location = {this.props.location}
onUpdate = {(...a) => this.onUpdate(...a)}
onReset = {(...a) => this.onReset(...a)}
/>
)}
else = {() => (
<LoginPane
data = {this.state}
location = {this.props.location}
onUpdate = {(...a) => this.onUpdate(...a)}
onLogin = {(...a) => this.onLogin(...a)}
/>
)}
/>
</Row>
</Container>
</div>
);
};
};