Esempio n. 1
0
        public async Task <object> Login([FromBody] LoginViewModel model)
        {
            GenerateToken token  = new GenerateToken(_configuration);
            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(await token.GenerateJwtToken(model.Email, appUser));
            }

            throw new ApplicationException("INVALID_LOGIN_ATTEMPT");
        }
Esempio n. 2
0
 public IActionResult Login([FromBody] LoginModel user)
 {
     if (user == null)
     {
         return(BadRequest("Invalid Client Request"));
     }
     if (user.UserName == "alok" && user.Password == "alok@123")
     {
         return(Ok(new { Token = GenerateToken.GenerateJwtToken(user.UserName) }));
     }
     else
     {
         return(Unauthorized());
     }
 }
Esempio n. 3
0
        public async Task <object> Register([FromBody] RegisterViewModel model)
        {
            var user = new IdentityUser
            {
                UserName = model.Email,
                Email    = model.Email
            };
            var result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                await _signInManager.SignInAsync(user, false);

                GenerateToken token = new GenerateToken(_configuration);
                return(await token.GenerateJwtToken(model.Email, user));
            }

            throw new ApplicationException("UNKNOWN_ERROR");
        }
Esempio n. 4
0
 public ActionResult <IEnumerable <string> > Get()
 {
     return(new string[] { ValidateToken.ValidateTokenServer(GenerateToken.GenerateJwtToken("10")) });
 }