-
Notifications
You must be signed in to change notification settings - Fork 0
/
identity-register.tsx
72 lines (60 loc) · 3.03 KB
/
identity-register.tsx
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
import * as ko from 'knockout';
import { validableObservable, isEmail, isRequired, areSame } from "folke-ko-validation";
import { React, ko_if, ko_ifnot, ko_foreach } from "kjsx";
import { Identity } from './identity';
import { getQueryString } from 'folke-service-helpers';
export default class IdentityRegisterViewModel<TKey> {
private email = validableObservable("").addValidator(isEmail).addValidator(isRequired);
private password = validableObservable("").addValidator(isRequired);
private confirmPassword = validableObservable("").addValidator(areSame(this.password));
private isValid = ko.pureComputed(() => !this.props.identity.loading() && this.email.valid() && this.password.valid() && this.confirmPassword.valid());
constructor(public props: { identity: Identity<TKey>, onRegister: () => void }) {
}
public render() {
return <section class="identity-popin popin">
<header>
{/* <popin-close-button></popin-close-button> */}
<div>identity.createAccounttitle</div>
</header>
<section>
<form submit={this.register}>
<fieldset class="large">
<label>identity.email</label>
<input type="text" textInput={this.email} validate={this.email}/>
</fieldset>
<fieldset class="large">
<label>identity.password</label>
<input type="password" textInput={this.password} validate={this.password}/>
</fieldset>
<fieldset class="large">
<label>identity.confirmPassword</label>
<input type="password" textInput={this.confirmPassword} validate={this.confirmPassword}/>
</fieldset>
<div>
<button type="submit" class="fit button" enable={this.isValid}>identity.signupButton</button>
</div>
</form>
</section>
<div class="separator">identity.or</div>
<section class="social">
<button class="button fit" click={this.facebookLogin}><span class="fa fa-facebook"></span> identity.signupSocial</button>
</section>
<footer>
identity.alreadyMember <a href="" click={this.login}>identity.loginButton</a>
</footer>
</section>;
}
public login = () => this.props.identity.goToLogin(this.props.onRegister) ;
public register = () => {
this.props.identity.services.authentication.register({ registerView: { email: this.email(), password: this.password(), confirmPassword: this.confirmPassword() } }).then(view => {
this.props.identity.hideEmailConfirmBar(true);
this.props.identity.account(view);
return view;
}).then(view => this.props.onRegister());
}
public dispose() {
}
public facebookLogin = () => {
window.open('/api/authentication/external-login' + getQueryString({ provider: 'Facebook', returnUrl: window.location.toString() }), 'oauth', 'dialog');
}
}