コード例 #1
0
        public ActionResult Login(string redirectUrl)
        {
            UserAuthenticationViewModel model = new UserAuthenticationViewModel();

            model.RedirectUrl = redirectUrl;
            return(View(model));
        }
コード例 #2
0
        public ActionResult LoginOn()
        {
            UserAuthenticationViewModel viewModel = new UserAuthenticationViewModel();

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

            return(View(viewModel));
        }
コード例 #3
0
 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));
 }
コード例 #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,
            }));
        }
コード例 #5
0
        public ActionResult Login()
        {
            UserAuthenticationViewModel model = new UserAuthenticationViewModel();

            return(View(model));
        }
コード例 #6
0
 public MainWindow()
 {
     InitializeComponent();
     DataContext = new UserAuthenticationViewModel(this);
 }