public AuthenticationResponse Authenticate(string username, string password)
        {
            if (IsInputInvalid(username, password))
            {
                return(new AuthenticationResponse
                {
                    Success = false,
                    Message = "Username or password are incorrect."
                });
            }

            AuthenticationServiceResponse authenticationReponse = _authenticationService.Authenticate(username, password);

            if (authenticationReponse == AuthenticationServiceResponse.Ok)
            {
                return new AuthenticationResponse
                       {
                           Success = true,
                           Message = "Login Succeeded."
                       }
            }
            ;
            else
            {
                return(new AuthenticationResponse
                {
                    Success = false,
                    Message = "Username or password are incorrect."
                });
            }
        }
Exemplo n.º 2
0
        public ActionResult SignIn(LoginViewModel loginViewModel)
        {
            UserModel userModel = new UserModel();

            Mapper.Map(loginViewModel, userModel);
            AuthenticationServiceResponse response = _authenticationService.SignInUser(userModel, true);

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
        public async Task <AuthenticationServiceResponse> SetPassword(int userId, string password)
        {
            AuthenticationServiceResponse response = new AuthenticationServiceResponse();

            UserManager.RemovePassword(userId);
            var result = await UserManager.AddPasswordAsync(userId, password);

            response.Success = result.Succeeded;
            response.Message = result.Errors.FirstOrDefault();

            var userInfo = UserManager.FindById(userId);//getting userInfo

            //userInfo.PasswordHash=password;
            response.Message = userInfo.UserName;

            return(response);
        }
Exemplo n.º 4
0
        public async Task <JsonResult> SignUp(UserViewModel userViewModel)
        {
            if (ModelState.IsValid && userViewModel != null)
            {
                UserModel userModel = new UserModel();
                Mapper.Map(userViewModel, userModel);
                userModel.FirstName         = userViewModel.FullName;
                userModel.CompanyModel.Name = userViewModel.CompanyName;


                var response = await _authenticationService.CreateUser(userModel);

                if (response.Success == true)
                {
                    //userModel.UserName = userModel.Email;
                    //userModel.Password = userModel.Password;
                    AuthenticationServiceResponse loginResponse = _authenticationService.SignInUser(userModel);
                }
                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { Message = "ModelState IsVaid is False", Success = false }, JsonRequestBehavior.AllowGet));
        }