示例#1
0
        public async Task <ApplicationActionResult <AuthResult> > Login(AuthModel authModel)
        {
            AuthResult authResult = new AuthResult();
            var        user       = await _userManager.FindByNameAsync(authModel.Login);

            if (user == null)
            {
                authResult.InvalidLogin();
                return(new ApplicationActionResult <AuthResult>(authResult, (int)Core.Constants.ActionStatuses.Fail, ""));
            }

            var checkPasswordResult = await _userManager.CheckPasswordAsync(user, authModel.Password);

            if (!checkPasswordResult)
            {
                authResult.InvalidPassword();
                return(new ApplicationActionResult <AuthResult>(authResult, (int)Core.Constants.ActionStatuses.Fail, ""));
            }

            JwtTokenModel token = await _tokenHelper.CreateJwtTokens(user);

            authResult.SuccessAuth(token);
            return(new ApplicationActionResult <AuthResult>(authResult, (int)Core.Constants.ActionStatuses.Success, ""));
        }