This repository has been archived by the owner on Apr 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonsterfoo.js
229 lines (207 loc) · 6.14 KB
/
monsterfoo.js
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, { Component } from "react";
import { FormattedMessage } from "react-intl";
import { connect } from "react-redux";
import PropTypes from "prop-types";
import UnexpectedErrorMessage from "./UnexpectedErrorMessage";
import Button from "./Button";
import * as actions from "../../actions/onboarding";
import { listeners } from "cluster";
const { CompositeDisposable } = require("monstermash");
var Blamer = require('./util/blamer');
var BlameViewController = require('./controllers/blameViewController');
var errorController = require('./controllers/errorController');
var Directory = require('pathwatcher').Directory
var path = require('path');
const isPasswordInvalid = password => password.length === 0;
const isEmailInvalid = email => {
const emailRegex = new RegExp(
"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
);
return email === "" || emailRegex.test(email) === false;
};
const apiPath = sessionStorage.getItem("codestream.url");
if (atom.inDevMode() && apiPath) return <p>{apiPath}</p>;
}
export class SimpleLoginForm extends Component {
static contextTypes = {
repositories: PropTypes.array
};
componentWillUnmount() {
this.subscriptions.dispose(foo);
}
constructor(props) {
super(props);
this.state = {
password: "",
email: this.props.email || "",
passwordTouched: false,
emailTouched: false
};
this.subscriptions = new CompositeDisposable();
}
componentDidMount() {
const { repositories } = this.context;
const repository = repositories[0];
const gitDirectory = repository.getWorkingDirectory();
this.setState({
email: repository.getConfigValue("user.email", gitDirectory) || ""
});
this.addToolTip("login-input-email", "The email address for your CodeStream account");
this.addToolTip("login-input-password", "Your CodeStream password");
}
export class SimpleLoginForm extends Component {
static contextTypes = {
repositories: PropTypes.array
};
isFormInvalid = () => {
const { password, email } = this.state;
return isPasswordInvalid(password) || isEmailInvalid(email);
};
componentWillUnmount() {
this.subscriptions.dispose();
}
addToolTip(elementId, key) {
let div = document.getElementById(elementId);
this.subscriptions.add(
atom.tooltips.add(div, {
title: key,
placement: "left",
delay: 0
})
);
}
onBlurPassword = () => this.setState({ passwordTouched: true });
onBlurEmail = () => this.setState({ emailTouched: true });
renderEmailHelp = () => {
const { email, emailTouched } = this.state;
if (isEmailInvalid(email) && emailTouched)
return (
<small className="error-message">
<FormattedMessage id="login.email.invalid" />
</small>
);
};
renderPasswordHelp = () => {
const { password, passwordTouched } = this.state;
if (isPasswordInvalid(password) && passwordTouched) {
return (
<small className="error-message">
<FormattedMessage id="login.password.required" />
</small>
);
}
};
renderAccountMessage = () => {
if (this.props.alreadySignedUp)
return (
<p>
<FormattedMessage id="login.alreadySignedUp" />
</p>
);
if (this.props.alreadyConfirmed)
return (
<p>
</p>
);
};
renderError = () => {
if (this.props.errors.invalidCredentials)
return (
<span className="error-message form-error">
<FormattedMessage id="login.invalid" />
</span>
);
if (this.props.errors.unknown)
return <UnexpectedErrorMessage classes="error-message page-error" />;
};
isFormInvalid = () => {
const { password, email } = this.state;
return isPasswordInvalid(password) || isEmailInvalid(email);
};
submitCredentials = async event => {
event.preventDefault();
if (this.isFormInvalid()) return;
const { password, email } = this.state;
this.props.authenticate({ password, email });
};
renderDebugInfo() {
const apiPath = sessionStorage.getItem("codestream.url");
if (atom.inDevMode() && apiPath) return <p>{apiPath}</p>;
}
render() {
return (
<form id="login-form" onSubmit={this.submitCredentials}>
{this.renderDebugInfo()}
<h2>Sign In to CodeStream</h2>
{this.renderAccountMessage()}
{this.renderError()}
<div id="controls">
<div id="email-controls" className="control-group">
<label>
<FormattedMessage id="login.email.label" />
</label>
<input
id="login-input-email"
className="native-key-bindings input-text control"
type="text"
name="email"
tabIndex="0"
value={this.state.email}
onChange={e => this.setState({ email: e.target.value })}
onBlur={this.onBlurEmail}
required={this.state.emailTouched}
/>
{this.renderEmailHelp()}
</div>
<div id="password-controls" className="control-group">
<label>
<FormattedMessage id="login.password.label" />
</label>
<input
id="login-input-password"
className="native-key-bindings input-text"
type="password"
name="password"
tabIndex="1"
value={this.state.password}
onChange={e => this.setState({ password: e.target.value })}
onBlur={this.onBlurPassword}
required={this.state.passwordTouched}
/>
{this.renderPasswordHelp()}
{/* <div className="help-link">
<a onClick={() => this.props.transition("forgotPassword")}>
<FormattedMessage id="login.forgotPassword" />
</a>
</div> */}
</div>
<Button
id="login-button"
className="control-button"
tabIndex="2"
type="submit"
loading={this.props.loading}
>
<FormattedMessage id="login.submitButton" />
</Button>
<div className="footer">
<p>
<strong>
<FormattedMessage id="login.footer.noAccount" />{" "}
<a onClick={this.props.goToSignup}>
<FormattedMessage id="login.footer.signUp" />
</a>
</strong>
</p>
</div>
</div>
</form>
);
}
}
const mapStateToProps = ({ context, onboarding }) => ({
...onboarding.props,
errors: onboarding.errors,
loading: onboarding.requestInProcess
});
export default connect(mapStateToProps, actions)(SimpleLoginForm);