/// <summary> /// execute when user submits user details to get registered /// </summary> private void RegisterUser() { User userDetails = new User(); userDetails.Email = Email; if (!HasErrors) { userDetails.Password = PasswordHash.HashPassword(Password); try { Int32 userId = _userDataAccessService.createUser(userDetails); if (userId > 0) { CurrentUser = UserDetailsHelper.getUserName(Email); App.Current.Properties["currentUserId"] = userId; RaisePropertyChanged("IsAuthenticated"); NavigateCommandAction("challengeSelector"); this.SignUpFlyoutIsVisible = false; Password = String.Empty; ConfirmPassword = String.Empty; Email = String.Empty; IsWarning = false; } } catch (Exception ex) { IsWarning = true; Status = String.Format("ERROR: {0}", ex.Message); } } }
/// <summary> /// execute when user submits login details /// </summary> private void LoginUser() { try { //Validate credentials through the authentication service User user = _authenticationService.authenticateUser(Email, Password); //Authenticate the user App.Current.Properties["currentUserId"] = user.UserId; //Update UI RaisePropertyChanged("IsAuthenticated"); CurrentUser = UserDetailsHelper.getUserName(user.Email);//set logged in user's username Status = String.Empty; if (IsWarning) { IsWarning = false; } NavigateCommandAction("manageNotificationMessages"); this.LoginFlyoutIsVisible = false; Password = String.Empty; //reset Email = String.Empty; //reset IsWarning = false; } catch (UnauthorizedAccessException) { IsWarning = true; Status = Properties.Resources.UnAuthorizedAccess; } catch (Exception ex) { IsWarning = true; Status = String.Format("ERROR: {0}", ex.Message); } }