public async Task <IRepositoryResult> Login(LoginParameter parameter)
        {
            var repositoryResult = await _accountBusiness.Login(parameter);

            var result = ResponseHandler.GetResult(repositoryResult);

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> DangNhap(string userName, string password, string rememberMe)
        {
            var account = await _bizAccount.Login(userName, password);

            if (account == null)
            {
                return(ToFailResponse());
            }
            if (!isValidAccount(account))
            {
                return(ToFailResponse());
            }

            List <Claim> claims = new List <Claim>();

            claims.Add(new Claim("Id", account.Id.ToString()));
            claims.Add(new Claim("UserName", account.UserName));
            if (!string.IsNullOrWhiteSpace(account.Email))
            {
                claims.Add(new Claim("Email", account.Email));
            }
            if (!string.IsNullOrWhiteSpace(account.Code))
            {
                claims.Add(new Claim("Code", account.Code));
            }
            if (!string.IsNullOrWhiteSpace(account.Role))
            {
                claims.Add(new Claim("Role", account.Role));
            }
            if (!string.IsNullOrWhiteSpace(account.Scope))
            {
                claims.Add(new Claim("Scope", String.Join(",", account.Scope)));
            }
            var userIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);

            ClaimsPrincipal principal      = new ClaimsPrincipal(userIdentity);
            var             authProperties = new AuthenticationProperties
            {
                IsPersistent = true
            };
            await HttpContext.SignInAsync(principal, authProperties);

            ViewBag.Account = account;
            return(ToResponse(account));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Login([FromBody] LoginDTO loginModel)
        {
            if (!ModelState.IsValid)
            {
                BadRequest();
            }

            var result = await accountBusiness.Login(loginModel);

            if (!result.Succeeded)
            {
                var errors = result.Errors.Select(x => x.Description).ToList();
                _logger.LogWarning(LogEvents.Register,
                                   "login errors: {errors} for user: {email}",
                                   errors, loginModel.Email);
                return(BadRequest(errors));
            }

            // generte token
            var token = await accountBusiness.GenerateJwtToken(loginModel);

            return(Ok(new { accesToken = token }));
        }
        public async Task <IActionResult> Login([FromBody] UserLoginParameter parameter)
        {
            var result = await _accountBusiness.Login(parameter);

            return(Ok(result));
        }