Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0306d41

Browse files
authored
Logout after socket connection closes (#79)
* Logout after socket connection closes * Change from logout() to resetUserState * Update error message for unactivated accounts
1 parent 696a1cc commit 0306d41

File tree

6 files changed

+26
-18
lines changed

6 files changed

+26
-18
lines changed

src/app/actions/User.ts

+1-16
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,7 @@ export namespace UserActions {
4949
export const updateErrorMessage = (errorMessage: string) =>
5050
action(Type.UPDATE_ERROR_MESSAGE, { errorMessage });
5151

52-
interface UserDetails {
53-
isLoggedIn: boolean;
54-
isFirstLogin?: boolean;
55-
userId?: number;
56-
avatar?: string;
57-
college?: string;
58-
userType?: UserInterfaces.UserType;
59-
fullName?: string;
60-
username?: string;
61-
email?: string;
62-
errorMessage?: string;
63-
country?: string;
64-
isUserProfileModalOpen?: boolean;
65-
}
66-
67-
export const updateUserDetails = (userDetails: UserDetails) =>
52+
export const updateUserDetails = (userDetails: UserInterfaces.UserDetails) =>
6853
action(Type.UPDATE_USER_DETAILS, { userDetails });
6954

7055
export const getUserDetails = () => action(Type.GET_USER_DETAILS);

src/app/components/SocketHandler.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ export class SocketHandler extends React.Component<SocketHandlerInterfaces.Props
8989
},
9090
// tslint:disable-next-line
9191
(closeEvent: any) => {
92-
// const { logout } = this.props;
93-
// logout();
92+
this.props.resetUserState();
9493
},
9594
);
9695
}

src/app/containers/SocketHandler.ts

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { RootState } from 'app/reducers';
44
import * as SubmissionInterfaces from 'app/types/code/Submission';
55
import * as NotificationInterfaces from 'app/types/Notification';
66
import * as SocketHandlerInterfaces from 'app/types/SocketHandler';
7+
import { UserDetails } from 'app/types/User';
78
import { connect } from 'react-redux';
89
import { Dispatch } from 'redux';
910

@@ -46,6 +47,7 @@ const mapDispatchToProps = (dispatch: Dispatch) => {
4647
info: (message: string) => dispatch(NotificationActions.info(message)),
4748
logout: () => dispatch(UserActions.logout()),
4849
resetNotificationState: () => dispatch(NotificationActions.resetNotificationState()),
50+
resetUserState: () => dispatch(UserActions.resetUserState()),
4951
sendCompileError: (error: string) => dispatch(SubmissionActions.handleCompileError(error)),
5052
sendCompileSuccess: () => dispatch(SubmissionActions.handleCompileSuccess()),
5153
sendDebugRunError: () => dispatch(SubmissionActions.handleDebugRunError()),
@@ -69,6 +71,7 @@ const mapDispatchToProps = (dispatch: Dispatch) => {
6971
dispatch(GameLogActions.updateMatchPlayerId(matchPlayerId)),
7072
updateRequest: (request: SubmissionInterfaces.Request) =>
7173
dispatch(SubmissionActions.changeCurrentRequest(request)),
74+
updateUserDetails: (details: UserDetails) => dispatch(UserActions.updateUserDetails(details)),
7275
};
7376
};
7477

src/app/sagas/User.ts

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export function* login(action: ActionType<typeof UserActions.login>) {
4949
let errorMessage;
5050
switch (responseBody.message) {
5151
case 'User is disabled':
52+
errorMessage = 'Please check your email to activate your account';
53+
break;
5254
case 'Bad credentials':
5355
errorMessage = 'Your email or password was incorrect.';
5456
break;
@@ -183,6 +185,7 @@ export function* getQuestStatus(action: ActionType<typeof UserActions.getQuestSt
183185
}
184186
} catch (err) {
185187
console.error(err);
188+
yield put(UserActions.resetUserState());
186189
}
187190
}
188191

src/app/types/SocketHandler.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as SubmissionInterfaces from 'app/types/code/Submission';
22
import * as NotificationInterfaces from 'app/types/Notification';
3+
import { UserDetails } from 'app/types/User';
34

45
export interface DispatchProps {
56
add: (type: NotificationInterfaces.NotificationType, title: string, text: string) => void;
@@ -16,6 +17,7 @@ export interface DispatchProps {
1617
info: (message: string) => void;
1718
logout: () => void;
1819
resetNotificationState: () => void;
20+
resetUserState: () => void;
1921
sendExecuteError: (error: string) => void;
2022
sendExecuteSuccess: (logs: string) => void;
2123
sendCompileError: (error: string) => void;
@@ -33,6 +35,7 @@ export interface DispatchProps {
3335
updateGlobalNotifications: (notifications: NotificationInterfaces.Notification[]) => void;
3436
updateMatchPlayerId: (matchPlayerId: number) => void;
3537
updateRequest: (request: SubmissionInterfaces.Request) => void;
38+
updateUserDetails: (details: UserDetails) => void;
3639
}
3740

3841
export enum MatchMode {

src/app/types/User.ts

+15
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ export interface ActivateUser {
4141
userId: number;
4242
}
4343

44+
export interface UserDetails {
45+
isLoggedIn: boolean;
46+
isFirstLogin?: boolean;
47+
userId?: number;
48+
avatar?: string;
49+
college?: string;
50+
userType?: UserType;
51+
fullName?: string;
52+
username?: string;
53+
email?: string;
54+
errorMessage?: string;
55+
country?: string;
56+
isUserProfileModalOpen?: boolean;
57+
}
58+
4459
const actions = {
4560
ActivateUser: UserActions.activateUser,
4661
editUserPassword: UserActions.editUserPassword,

0 commit comments

Comments
 (0)