Change Email functional, create and add UserOptions model
This commit is contained in:
parent
11a06d124e
commit
2dff84b33f
@ -1,15 +1,12 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
|
||||||
import { UserSettingsService } from './user-settings.service';
|
import { UserSettingsService } from './user-settings.service';
|
||||||
import {
|
import { PassForm, UsernameForm, EmailForm } from './user-settings.models';
|
||||||
PassForm,
|
|
||||||
UsernameForm,
|
|
||||||
EmailForm
|
|
||||||
} from './user-settings.models';
|
|
||||||
import {
|
import {
|
||||||
AuthService,
|
AuthService,
|
||||||
NotificationsService,
|
NotificationsService,
|
||||||
User,
|
User,
|
||||||
|
UserOptions,
|
||||||
Notification,
|
Notification,
|
||||||
ApiResponse
|
ApiResponse
|
||||||
} from '../../shared/index';
|
} from '../../shared/index';
|
||||||
@ -21,14 +18,21 @@ import {
|
|||||||
})
|
})
|
||||||
export class UserSettings implements OnInit {
|
export class UserSettings implements OnInit {
|
||||||
private user: User;
|
private user: User;
|
||||||
|
private userOptions: UserOptions;
|
||||||
private changePassword: PassForm;
|
private changePassword: PassForm;
|
||||||
private changeUsername: UsernameForm;
|
private changeUsername: UsernameForm;
|
||||||
private changeEmail: EmailForm
|
private changeEmail: EmailForm;
|
||||||
|
|
||||||
constructor(private auth: AuthService,
|
constructor(private auth: AuthService,
|
||||||
private notes: NotificationsService,
|
private notes: NotificationsService,
|
||||||
private userService: UserSettingsService) {
|
private userService: UserSettingsService) {
|
||||||
auth.userChanged.subscribe(user => this.user = user);
|
this.changeEmail = new EmailForm();
|
||||||
|
|
||||||
|
auth.userChanged.subscribe(user => {
|
||||||
|
this.user = user;
|
||||||
|
this.changeEmail.newEmail = user.email;
|
||||||
|
this.userOptions = auth.userOptions;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@ -42,9 +46,8 @@ export class UserSettings implements OnInit {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.userService
|
this.userService.changePassword(this.changePassword.current,
|
||||||
.changePassword(this.changePassword.current,
|
this.changePassword.newPass)
|
||||||
this.changePassword.newPass)
|
|
||||||
.subscribe((response: ApiResponse) => {
|
.subscribe((response: ApiResponse) => {
|
||||||
this.addAlerts(response.alerts);
|
this.addAlerts(response.alerts);
|
||||||
this.resetPasswordForm();
|
this.resetPasswordForm();
|
||||||
@ -63,8 +66,7 @@ export class UserSettings implements OnInit {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.userService
|
this.userService.changeUsername(this.changeUsername.newName)
|
||||||
.changeUsername(this.changeUsername.newName)
|
|
||||||
.subscribe((response: ApiResponse) => {
|
.subscribe((response: ApiResponse) => {
|
||||||
this.addAlerts(response.alerts);
|
this.addAlerts(response.alerts);
|
||||||
this.resetUsernameForm();
|
this.resetUsernameForm();
|
||||||
@ -75,7 +77,8 @@ export class UserSettings implements OnInit {
|
|||||||
updateEmail() {
|
updateEmail() {
|
||||||
this.changeEmail.submitted = true;
|
this.changeEmail.submitted = true;
|
||||||
|
|
||||||
let emailRegex = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
|
// https://davidcel.is/posts/stop-validating-email-addresses-with-regex/
|
||||||
|
let emailRegex = /.+@.+\..+/i;
|
||||||
let match = this.changeEmail.newEmail.match(emailRegex);
|
let match = this.changeEmail.newEmail.match(emailRegex);
|
||||||
|
|
||||||
if (!match && this.changeEmail.newEmail !== '') {
|
if (!match && this.changeEmail.newEmail !== '') {
|
||||||
@ -86,8 +89,7 @@ export class UserSettings implements OnInit {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.userService
|
this.userService.changeEmail(this.changeEmail.newEmail)
|
||||||
.changeEmail(this.changeEmail.newEmail)
|
|
||||||
.subscribe((response: ApiResponse) => {
|
.subscribe((response: ApiResponse) => {
|
||||||
this.addAlerts(response.alerts);
|
this.addAlerts(response.alerts);
|
||||||
this.resetEmailForm();
|
this.resetEmailForm();
|
||||||
|
@ -64,12 +64,19 @@ export class UserSettingsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
changeEmail(newEmail: string): Observable<ApiResponse> {
|
changeEmail(newEmail: string): Observable<ApiResponse> {
|
||||||
let json = JSON.stringify(this.activeUser);
|
let updateUser = this.activeUser;
|
||||||
|
updateUser.email = newEmail;
|
||||||
|
|
||||||
|
let json = JSON.stringify(updateUser);
|
||||||
|
|
||||||
return this.http.post('api/users/' + this.activeUser.id, json)
|
return this.http.post('api/users/' + this.activeUser.id, json)
|
||||||
.map(res => {
|
.map(res => {
|
||||||
let response: ApiResponse = res.json();
|
let response: ApiResponse = res.json();
|
||||||
return response;
|
return response;
|
||||||
|
})
|
||||||
|
.catch((res, caught) => {
|
||||||
|
let response: ApiResponse = res.json();
|
||||||
|
return Observable.of(response);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
export * from './user.model';
|
export * from './user.model';
|
||||||
export * from './api-response.model';
|
export * from './api-response.model';
|
||||||
export * from './notification.model';
|
export * from './notification.model';
|
||||||
|
export * from './user-options.model';
|
||||||
|
|
||||||
|
8
src/app/shared/models/user-options.model.ts
Normal file
8
src/app/shared/models/user-options.model.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
export interface UserOptions {
|
||||||
|
id: number;
|
||||||
|
new_tasks_at_bottom: boolean;
|
||||||
|
show_animations: boolean;
|
||||||
|
show_assignee: boolean;
|
||||||
|
multiple_tasks_per_row: boolean;
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user