Exemple #1
0
        public async Task <IActionResult> Login([FromBody] AccountViewModel model)
        {
            ResultModel result = new ResultModel();

            if (ModelState.IsValid)
            {
                var signResult = await _signInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, false);

                if (signResult.Succeeded)
                {
                    var user = await _userManager.Users.FirstOrDefaultAsync(i => i.NormalizedUserName.Equals(model.UserName.ToUpper()));

                    var token = _jwtHelper.GetToken(user.Id);
                    var key   = _jwtHelper.GetTokenValue(token);
                    result.Succeeded = true;
                    UserData data = new UserData(key, User.GetUserId());
                    result.Data = data;
                }
                else if (signResult.IsNotAllowed)
                {
                    result.Message = "The user is banned.";
                }
                else
                {
                    result.Message = "User informations are wrong.";
                }
            }

            return(Json(result));
        }
        // An example token generator
        public IActionResult Login()
        {
            var token = _jwtHelper.GetToken("deneme");
            var key   = _jwtHelper.GetTokenValue(token);

            return(Json(key));
        }