Ejemplo n.º 1
0
        public ActionResult Login(string redirectUrl)
        {
            UserAuthenticationViewModel model = new UserAuthenticationViewModel();

            model.RedirectUrl = redirectUrl;
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult LoginOn()
        {
            UserAuthenticationViewModel viewModel = new UserAuthenticationViewModel();

            viewModel.UserRegister = new UserRegisterViewModel();
            viewModel.UserSignIn   = new UserSignInViewModel();

            return(View(viewModel));
        }
 public ActionResult Login(UserAuthenticationViewModel model)
 {
     TryUpdateModel(model);
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     AthenticationService.Authenticate(model.Email, model.Password);
     if (AthenticationService.LoggedUser != null)
     {
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
Ejemplo n.º 4
0
        public async Task <IActionResult> Authenticate([FromBody] UserAuthenticationViewModel model)
        {
            User user = await _userService.Authenticate(model.Username, model.Password);

            if (user == null)
            {
                return(BadRequest("Username or password is incorrect."));
            }

            JwtSecurityTokenHandler tokenHandler = new JwtSecurityTokenHandler();

            byte[] key = Encoding.UTF8.GetBytes(_config.GetValue <String>("Secrets:Jwt"));
            SecurityTokenDescriptor tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new Claim[]
                {
                    new Claim(ClaimTypes.Name, user.Id.ToString())
                }),
                Expires            = DateTime.UtcNow.AddDays(7),
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
            };

            SecurityToken token       = tokenHandler.CreateToken(tokenDescriptor);
            string        tokenString = tokenHandler.WriteToken(token);

            // Return basic user information(without password) and token to be stored at client side.
            return(Ok(new
            {
                Id = user.Id,
                Username = user.Username,
                FirstName = user.FirstName,
                LastName = user.LastName,
                Email = user.Email,
                Token = tokenString,
            }));
        }
        public ActionResult Login()
        {
            UserAuthenticationViewModel model = new UserAuthenticationViewModel();

            return(View(model));
        }
Ejemplo n.º 6
0
 public MainWindow()
 {
     InitializeComponent();
     DataContext = new UserAuthenticationViewModel(this);
 }