コード例 #1
0
        public async Task <LoginAccountResponseView> Login(LoginAccountView model)
        {
            var user = await _userManager.FindByNameAsync(model.UserName);

            if (user == null)
            {
                throw new CustomServiceException("Player does not exist.");
            }

            var isValidPassword = await _userManager.CheckPasswordAsync(user, model.Password);

            if (!isValidPassword)
            {
                throw new CustomServiceException("Invalid username or password.");
            }

            var    email = (!string.IsNullOrEmpty(model.Email)) ? model.Email : "";
            string token = await _jwtProvider.GenerateJwtToken(email, user);

            var result = new LoginAccountResponseView()
            {
                AccessToken = token,
                UserName    = user.UserName,
                PlayerId    = user.Id
            };

            return(result);
        }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: mexbi1/BookStore
        public async Task <IActionResult> Login(LoginAccountView model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByNameAsync(model.Email);

                if (user != null)
                {
                    // проверяем, подтвержден ли email
                    if (!await _userManager.IsEmailConfirmedAsync(user))
                    {
                        ModelState.AddModelError(string.Empty, "Вы не подтвердили свой email");
                        return(Ok(model));
                    }
                }

                var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, false);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Неправильный логин и (или) пароль");
                }
            }
            return(Ok(model));
        }
コード例 #3
0
        public async Task <JwtView> Login(LoginAccountView view)
        {
            User    user  = _mapper.Map <LoginAccountView, User>(view);
            JwtView token = _jwtProvider.CreateToken(user);

            return(token);
        }
コード例 #4
0
        public async Task <GenericResponseView <LoginAccountResponseView> > Login([FromBody] LoginAccountView model)
        {
            var response = new GenericResponseView <LoginAccountResponseView>();

            response.Model = await _accountService.Login(model);

            return(response);
        }
コード例 #5
0
ファイル: AccountService.cs プロジェクト: mexbi1/BookStore
        public async Task <object> Login([FromBody] LoginAccountView model)
        {
            var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, false, false);

            if (result.Succeeded)
            {
                var appUser = _userManager.Users.SingleOrDefault(r => r.Email == model.Email);
                return(GenerateJwtToken(model.Email, appUser));
            }
            throw new ApplicationException("Invalid_Login_Attemp");
        }
コード例 #6
0
        public async Task <LoginAccountResponseView> Login(LoginAccountView model)
        {
            var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, false, false);

            if (!result.Succeeded)
            {
                throw new CustomServiceException("Invalid Login or password");
            }
            var user = await _userManager.FindByEmailAsync(model.Email);

            var encodedJwt = await _jwtProvider.GenerateJwtToken(user);

            var response = new LoginAccountResponseView()
            {
                Token = encodedJwt
            };

            return(response);
        }
コード例 #7
0
        public async Task <LoginAccountResponseView> Login(LoginAccountView model)
        {
            var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, false, false);

            if (!result.Succeeded)
            {
                throw new CustomServiceException("Invalid login attempt");
            }

            var user = await _userManager.FindByEmailAsync(model.Email);

            var token    = _jwtTokentHelper.GenerateJwtToken(model.Email, user);
            var response = new LoginAccountResponseView()
            {
                Token = token
            };

            return(response);
        }
コード例 #8
0
ファイル: AccountService.cs プロジェクト: dimals123/BJ.WEB
        public async Task <LoginAccountResponseView> Login(LoginAccountView model)
        {
            var result = await _userManager.FindByNameAsync(model.Name);

            var identityResult = await _signInManager.UserManager.CheckPasswordAsync(result, model.Password);

            if (!identityResult)
            {
                throw new ValidationException("Wrong login or password!");
            }


            var token    = _jwtTokentHelper.GenerateJwtToken(result);
            var response = new LoginAccountResponseView()
            {
                UserId = result.Id,
                Token  = token
            };

            return(response);
        }
コード例 #9
0
        public async Task <IActionResult> Login([FromBody] LoginAccountView model)
        {
            var response = await _accountService.Login(model);

            return(Ok(response));
        }
コード例 #10
0
 public async Task <IActionResult> Login([FromBody] LoginAccountView model)
 {
     return(await Execute(() => _accountService.Login(model)));
 }
コード例 #11
0
        public async Task <IActionResult> Login([FromBody] LoginAccountView view)
        {
            JwtView token = await _accountService.Login(view);

            return(Ok(token));
        }