public void Login() { // Create a new login command var request = new LoginRequestMsg(User.Email, User.Passwords[0]); var response = _clientMessenger.SendMessage(request); var loginResponse = (LoginResponseMsg) response; if (loginResponse.LoginSuccessful) { // Save token var session = Session.SharedSession; session.TokenString = loginResponse.TokenString; session.UserName = User.Email; // Notify view _view.LoginAccepted (); } else { // Reset password and display message _view.SetPasswordText(""); _view.DisplayAlert("Login Error", loginResponse.MessageInfo); } }
// Non-Token Messages private Message ResponseForLoginRequestMessage(LoginRequestMsg message) { return new LoginResponseMsg ("tokenString", true); }
private LoginResponseMsg HandleLoginRequest(LoginRequestMsg loginMsg) { try { var task = Task.Run(() => _smartpoolDb.UserAccess.ValidatePassword(loginMsg.Username, loginMsg.Password)); if (task.Wait(TimeSpan.FromSeconds(15))) //if task is completed within time limit { return task.Result ? new LoginResponseMsg(_tokenKeeper.CreateNewToken(loginMsg.Username), true) : new LoginResponseMsg("", false) {MessageInfo = "Username or password was incorrect"}; } else return new LoginResponseMsg("", false) {MessageInfo = "Login timed out. Please try again later"}; } catch (Exception e) { if (e.InnerException is UserNotFoundException) { return new LoginResponseMsg("", false) { MessageInfo = "User not found. Please try again" }; } Console.Write(e.ToString()); return new LoginResponseMsg("", false) { MessageInfo = "Failed to login.\nPlease try again or contact helpdesk" }; } }