Example #1
0
        public async Task <IActionResult> LoginAsync(LoginViewModel model)
        {
            var login = await _repo.Login(model);

            return(Json(new Metadata()
            {
                status = login, data = login ? (string.IsNullOrWhiteSpace(model.ReturnUrl) ? "/" : model.ReturnUrl) : "Login Failed"
            }));
        }
Example #2
0
 public IActionResult LoginAuthentication(LoginRequest loginRequest)
 {
     try
     {
         User   currentUser = _login.Login(loginRequest);
         string authHeader  = _login.AuthString(currentUser);
         return(Ok(authHeader));
     }
     catch (Exception e)
     {
         return(BadRequest());
     }
 }
Example #3
0
        public IActionResult Login(LoginModel loginModel)
        {
            var loginresponse = iloginRepo.Login(loginModel); //calling interface method

            if (loginresponse > 0)
            {
                //create token here
                var secretKey         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("superSecretKey@345"));
                var signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256);

                var tokeOptions = new JwtSecurityToken(
                    issuer: "http://localhost:61895",
                    audience: "http://localhost:4200",
                    claims: new List <Claim>(),
                    expires: DateTime.Now.AddMinutes(125),
                    signingCredentials: signinCredentials
                    );

                var tokenString = new JwtSecurityTokenHandler().WriteToken(tokeOptions);
                return(Ok(new { Token = tokenString, loginModel.UserName, loginresponse }));
            }
            return(BadRequest());
        }