#328494 Login user after successful registration. Fix settings screen to show unupdated values if update request fails.

This commit is contained in:
Georgi Prodanov 2017-02-07 11:25:16 +02:00
Родитель 601580e168
Коммит 5600899b66
3 изменённых файлов: 31 добавлений и 12 удалений

Просмотреть файл

@ -65,10 +65,12 @@ export class UsersService {
return this._isLoggedInSubj;
}
updateUser(user: User) {
user = this._sanitizeUser(user);
user.Email = user.Username;
let updatePromise = this._users.updateSingle(user);
updateUser(user: User)
updateUser(updateObject: any)
updateUser(userOrUpdateObj: any) {
userOrUpdateObj = this._sanitizeUser(userOrUpdateObj);
userOrUpdateObj.Email = userOrUpdateObj.Username;
let updatePromise = this._users.updateSingle(userOrUpdateObj);
// dont chain so returned promise doesnt have the cache clearing
updatePromise.then(() => this._currUserCache = null);
return updatePromise;

Просмотреть файл

@ -12,7 +12,8 @@ import { UsersService, AlertService } from '../../services';
styleUrls: [ 'settings/settings/settings.component.css' ]
})
export class SettingsComponent implements OnInit {
user: User;
user: { PushNotificationsEnabled: boolean, EmailNotificationsEnabled: boolean } = {} as any;
private _currentUser: User;
constructor(
private _usersService: UsersService,
@ -22,12 +23,29 @@ export class SettingsComponent implements OnInit {
ngOnInit() {
this._page.actionBar.title = 'Settings';
this._usersService.currentUser().then(user => this.user = user);
this._usersService.currentUser().then(user => {
this._currentUser = user;
this.user = {
PushNotificationsEnabled: this._currentUser.PushNotificationsEnabled,
EmailNotificationsEnabled: this._currentUser.EmailNotificationsEnabled
};
});
}
onSave() {
this._usersService.updateUser(this.user)
let updateObj = {
Id: this._currentUser.Id,
PushNotificationsEnabled: this.user.PushNotificationsEnabled,
EmailNotificationsEnabled: this.user.EmailNotificationsEnabled
};
this._usersService.updateUser(updateObj)
.then(() => this._alertsService.showSuccess('Settings saved'))
.catch(err => err && this._alertsService.showError(err.message));
.catch(err => {
if (err) {
this._alertsService.showError(err.message);
}
this.user.EmailNotificationsEnabled = this._currentUser.EmailNotificationsEnabled;
this.user.PushNotificationsEnabled = this._currentUser.PushNotificationsEnabled;
});
}
}

Просмотреть файл

@ -63,11 +63,10 @@ export class LoginComponent implements OnInit {
this._usersService.register(this.user.Username, this.user.Password, this.user.DisplayName)
.then((res) => {
this.changeView(false);
this._alertsService.showSuccess('Welcome to TeamUP!');
return this._usersService.login(this.user.Username, this.user.Password);
})
.catch((e) => {
this._alertsService.showError(e && e.message);
});
.catch((e) => e && this._alertsService.showError(e.message));
}
resetPassword() {