public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            try
            {
                // Verification.
                if (ModelState.IsValid)
                {
                    // Initialization.
                    var loginInfo = ssoService.Login(model.UserName, model.Password);

                    // Verification.
                    if (loginInfo != null)
                    {
                        // Login In.
                        this.SignInUser(loginInfo, false);
                        // Info.
                        return(this.RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        // Setting.
                        ModelState.AddModelError(string.Empty, "Invalid username or password.");
                    }
                }
            }
            catch (Exception ex)
            {
                // Info
                Console.Write(ex);
            }
            // If we got this far, something failed, redisplay form
            return(this.View(model));
        }
Exemplo n.º 2
0
        public async Task <LoginResponseModel> Login(string email, string password)
        {
            var response = await _userService.GetUserByEmail(email);

            if (response.ResponseCode == ResponseCode.NotFound)
            {
                throw new BadRequestException("User does not exist");
            }
            else if (response.ResponseCode == ResponseCode.Ok)
            {
                var result = await _ssoService.Login(new LoginDto { UserName = email, Password = password });

                if (result.ResponseCode != ResponseCode.Ok)
                {
                    throw new BadRequestException(result.Message);
                }

                return(new LoginResponseModel {
                    Token = result.ResponseData.access_token, User = response.ResponseData
                });
            }
            throw new Exception("An error occured");
        }