Skip to content

Commit 46f5c0d

Browse files
authored
Merge pull request #44 from gitcomteam/feature/34-lazy-registration
feature/34 lazy sign in
2 parents f9c5444 + d633ff0 commit 46f5c0d

File tree

13 files changed

+1517
-1052
lines changed

13 files changed

+1517
-1052
lines changed

public/img/bg/index.jpg

219 KB
Loading

src/app.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ p, b {
135135
border: 2px solid gray;
136136
}
137137

138+
.text-white {
139+
color: white !important;
140+
}
141+
138142
@media only screen and (min-width: 767px) {
139143
.desktop-zero-height {
140144
height: 0;

src/client/models/index.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,20 @@ export interface PostRegisterOKResponse {
278278
data?: PostRegisterOKResponseData;
279279
}
280280

281+
/**
282+
* An interface representing PostLazyRegisterOKResponseData.
283+
*/
284+
export interface PostLazyRegisterOKResponseData {
285+
token?: string;
286+
}
287+
288+
/**
289+
* An interface representing PostLazyRegisterOKResponse.
290+
*/
291+
export interface PostLazyRegisterOKResponse {
292+
data?: PostLazyRegisterOKResponseData;
293+
}
294+
281295
/**
282296
* An interface representing PostConfirmEmailOKResponseData.
283297
*/
@@ -1230,6 +1244,26 @@ export type PostRegisterResponse = PostRegisterOKResponse & {
12301244
};
12311245
};
12321246

1247+
/**
1248+
* Contains response data for the postLazyRegister operation.
1249+
*/
1250+
export type PostLazyRegisterResponse = PostLazyRegisterOKResponse & {
1251+
/**
1252+
* The underlying HTTP response.
1253+
*/
1254+
_response: msRest.HttpResponse & {
1255+
/**
1256+
* The response body as text (string format)
1257+
*/
1258+
bodyAsText: string;
1259+
1260+
/**
1261+
* The response body as parsed JSON or XML
1262+
*/
1263+
parsedBody: PostLazyRegisterOKResponse;
1264+
};
1265+
};
1266+
12331267
/**
12341268
* Contains response data for the postConfirmEmail operation.
12351269
*/

src/client/models/mappers.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,39 @@ export const PostRegisterOKResponse: msRest.CompositeMapper = {
874874
}
875875
};
876876

877+
export const PostLazyRegisterOKResponseData: msRest.CompositeMapper = {
878+
serializedName: "PostLazyRegisterOKResponse_data",
879+
type: {
880+
name: "Composite",
881+
className: "PostLazyRegisterOKResponseData",
882+
modelProperties: {
883+
token: {
884+
serializedName: "token",
885+
type: {
886+
name: "String"
887+
}
888+
}
889+
}
890+
}
891+
};
892+
893+
export const PostLazyRegisterOKResponse: msRest.CompositeMapper = {
894+
serializedName: "PostLazyRegisterOKResponse",
895+
type: {
896+
name: "Composite",
897+
className: "PostLazyRegisterOKResponse",
898+
modelProperties: {
899+
data: {
900+
serializedName: "data",
901+
type: {
902+
name: "Composite",
903+
className: "PostLazyRegisterOKResponseData"
904+
}
905+
}
906+
}
907+
}
908+
};
909+
877910
export const PostConfirmEmailOKResponseData: msRest.CompositeMapper = {
878911
serializedName: "PostConfirmEmailOKResponse_data",
879912
type: {

src/client/supportHubApi.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,33 @@ class SupportHubApi extends SupportHubApiContext {
7979
callback) as Promise<Models.PostRegisterResponse>;
8080
}
8181

82+
/**
83+
* @param email
84+
* @param [options] The optional parameters
85+
* @returns Promise<Models.PostLazyRegisterResponse>
86+
*/
87+
postLazyRegister(email: string, options?: msRest.RequestOptionsBase): Promise<Models.PostLazyRegisterResponse>;
88+
/**
89+
* @param email
90+
* @param callback The callback
91+
*/
92+
postLazyRegister(email: string, callback: msRest.ServiceCallback<Models.PostLazyRegisterOKResponse>): void;
93+
/**
94+
* @param email
95+
* @param options The optional parameters
96+
* @param callback The callback
97+
*/
98+
postLazyRegister(email: string, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback<Models.PostLazyRegisterOKResponse>): void;
99+
postLazyRegister(email: string, options?: msRest.RequestOptionsBase | msRest.ServiceCallback<Models.PostLazyRegisterOKResponse>, callback?: msRest.ServiceCallback<Models.PostLazyRegisterOKResponse>): Promise<Models.PostLazyRegisterResponse> {
100+
return this.sendOperationRequest(
101+
{
102+
email,
103+
options
104+
},
105+
postLazyRegisterOperationSpec,
106+
callback) as Promise<Models.PostLazyRegisterResponse>;
107+
}
108+
82109
/**
83110
* @param confirmationKey
84111
* @param [options] The optional parameters
@@ -1499,6 +1526,21 @@ const postRegisterOperationSpec: msRest.OperationSpec = {
14991526
serializer
15001527
};
15011528

1529+
const postLazyRegisterOperationSpec: msRest.OperationSpec = {
1530+
httpMethod: "POST",
1531+
path: "api/v1/lazy_register",
1532+
queryParameters: [
1533+
Parameters.email1
1534+
],
1535+
responses: {
1536+
200: {
1537+
bodyMapper: Mappers.PostLazyRegisterOKResponse
1538+
},
1539+
default: {}
1540+
},
1541+
serializer
1542+
};
1543+
15021544
const postConfirmEmailOperationSpec: msRest.OperationSpec = {
15031545
httpMethod: "POST",
15041546
path: "api/v1/register/confirm_email",

src/client/supportHubApiContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class SupportHubApiContext extends msRest.ServiceClient {
3636

3737
super(undefined, options);
3838

39-
this.baseUri = options.baseUri || this.baseUri || "http://api.gitcom.com/api/v1";
39+
this.baseUri = options.baseUri || this.baseUri || "http://api.gitcom.org/api/v1";
4040
this.requestContentType = "application/json; charset=utf-8";
4141
this.entityType = entityType;
4242
if (options.currencyType !== null && options.currencyType !== undefined) {
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import React from "react";
2+
import {Button, Divider, Form, Icon, Input, notification, Row} from "antd";
3+
import {Link} from "react-router-dom";
4+
5+
interface IProps {
6+
}
7+
8+
interface IState {
9+
form: {
10+
email: string
11+
}
12+
}
13+
14+
class FastAuth extends React.Component<IProps, IState> {
15+
constructor(props: IProps) {
16+
super(props);
17+
this.state = {
18+
form: {
19+
email: ""
20+
}
21+
}
22+
}
23+
24+
25+
updateForm(field: string, val: string) {
26+
let form: any = this.state.form;
27+
form[field] = val;
28+
this.setState({form});
29+
}
30+
31+
lazyEmailSignIn() {
32+
if (
33+
this.state.form.email.split('@').length === 1 ||
34+
this.state.form.email.split('.').length === 1
35+
) {
36+
notification['warning']({
37+
message: 'This email is invalid, please check your email and try again'
38+
});
39+
return;
40+
}
41+
window.location.replace(`/login?email=${this.state.form.email}`);
42+
}
43+
44+
render() {
45+
return <div>
46+
<Row>
47+
<div className="margin-sm-bottom">
48+
<Input
49+
name={"email"}
50+
prefix={<Icon type="mail" style={{color: 'rgba(0,0,0,.25)'}}/>}
51+
placeholder="Email"
52+
onChange={(e) => {
53+
this.updateForm('email', e.target.value)
54+
}}
55+
/>
56+
</div>
57+
<Row className="margin-sm-top">
58+
<Button
59+
type="primary"
60+
htmlType="submit"
61+
className="login-form-button"
62+
onClick={() => this.lazyEmailSignIn()}
63+
>Sign in</Button>
64+
</Row>
65+
66+
<Divider/>
67+
68+
<p>Or sign in with these services:</p>
69+
70+
<Row>
71+
<Link to={"/login?fast_signin=github"}>
72+
<Button icon={"github"}>GitHub</Button>
73+
</Link>
74+
<Link to={"/login?fast_signin=github"}>
75+
<Button className={"margin-sm-sides"} icon={"google"}>Google</Button>
76+
</Link>
77+
<Link to={"/login?fast_signin=gitlab"}>
78+
<Button icon={"gitlab"}>GitLab</Button>
79+
</Link>
80+
</Row>
81+
</Row>
82+
</div>
83+
}
84+
}
85+
86+
export default FastAuth;

src/components/external/auth/connectButton/ConnectButton.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ class ConnectButton extends React.Component<IProps, IState> {
5858
isLoaded: true,
5959
loginUrl: data.login_link
6060
});
61+
62+
setTimeout(() => {
63+
const fastSignIn = new URL(window.location.href).searchParams.get('fast_signin');
64+
if (fastSignIn === this.props.service) {
65+
window.location.replace(data.login_link);
66+
}
67+
}, 100);
6168
}
6269

6370
render() {

src/components/external/auth/googleButton/GoogleLoginButton.tsx

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,63 @@ import { Redirect } from 'react-router';
55
import {handleApiError} from "../../../../classes/notification/errorHandler/errorHandler";
66

77
interface IProps {
8-
classNames: string
8+
classNames: string,
9+
triggerOnRender: boolean,
910
}
1011

1112
interface IState {
1213
loggedIn: boolean,
1314
isLoading: boolean,
14-
redirect: boolean
15+
redirect: boolean,
16+
forceClickEvent: any,
17+
googleButton: any
1518
}
1619

1720
class GoogleLoginButton extends React.Component<IProps, IState> {
1821
public static defaultProps = {
19-
classNames: ""
22+
classNames: "",
23+
triggerOnRender: false
2024
};
2125

2226
constructor(props: IProps) {
2327
super(props);
2428
this.state = {
2529
loggedIn: false,
2630
isLoading: false,
27-
redirect: false
31+
redirect: false,
32+
forceClickEvent: null,
33+
googleButton: null
2834
};
2935
}
3036

37+
componentDidMount(): void {
38+
this.setState({
39+
googleButton: <GoogleLogin
40+
clientId={window.AppConfig.auth.external.google.client_id}
41+
render={renderProps => {
42+
this.setState({forceClickEvent: renderProps.onClick});
43+
return <Button
44+
icon={"google"}
45+
loading={this.state.isLoading}
46+
onClick={renderProps.onClick}
47+
disabled={renderProps.disabled}
48+
>via Google</Button>
49+
}}
50+
buttonText="Login"
51+
onSuccess={this.googleProcessOk.bind(this)}
52+
onFailure={err => console.error(err)}
53+
cookiePolicy={'single_host_origin'}
54+
/>
55+
});
56+
57+
const fastSignIn = new URL(window.location.href).searchParams.get('fast_signin');
58+
if (fastSignIn === "google") {
59+
setTimeout(() => {
60+
this.state.forceClickEvent();
61+
}, 100);
62+
}
63+
}
64+
3165
googleProcessOk(data: any) {
3266
window.App.apiClient.loginViaGoogle(data.Zi.access_token)
3367
.then((result) =>
@@ -39,10 +73,6 @@ class GoogleLoginButton extends React.Component<IProps, IState> {
3973
});
4074
}
4175

42-
googleProcessFail(data: any) {
43-
console.error(data);
44-
}
45-
4676
processGetMyToken(response: any) {
4777
let data = JSON.parse(response.bodyAsText).data;
4878
window.App.setApiToken(data.token);
@@ -57,21 +87,7 @@ class GoogleLoginButton extends React.Component<IProps, IState> {
5787
}
5888

5989
return <div className={this.props.classNames}>
60-
<GoogleLogin
61-
clientId={window.AppConfig.auth.external.google.client_id}
62-
render={renderProps => (
63-
<Button
64-
icon={"google"}
65-
loading={this.state.isLoading}
66-
onClick={renderProps.onClick}
67-
disabled={renderProps.disabled}
68-
>via Google</Button>
69-
)}
70-
buttonText="Login"
71-
onSuccess={this.googleProcessOk.bind(this)}
72-
onFailure={this.googleProcessFail.bind(this)}
73-
cookiePolicy={'single_host_origin'}
74-
/>
90+
{this.state.googleButton}
7591
</div>;
7692
}
7793
}

0 commit comments

Comments
 (0)