public async Task <IActionResult> Registration(RegistrationModel model) { if (ModelState.IsValid) { var user = await _userRepository.Users.FirstOrDefaultAsync(u => u.Email == model.Email); if (user == null) { _userRepository.InsertAsync( new User { Email = model.Email, Password = model.Password, Firstname = model.FirstName, Lastname = model.LastName, RegDate = DateTime.Today }); await _authenticateService.Authenticate(model.Email, HttpContext); return(RedirectToAction("Index", "Main")); } ModelState.AddModelError("", "Such user exists"); } return(View(model)); }
public async Task <ActionResult <AuthenticatedUser> > Authenticate([FromBody] LoginCredentials credentials) { var user = await _authenticateService.Authenticate(credentials); if (user == null) { return(BadRequest(new { message = "Bad email or password" })); } return(Ok(user)); }
public async Task <ActionResult <AuthenticatedUser> > Authenticate([FromBody] LoginCredentials credentials) { var user = await _authenticateService.Authenticate(credentials); if (user == null) { return(BadRequest(new { message = "Имя пользователя или пароль не корректны" })); } return(Ok(user)); }
public async Task <ActionResult> LoginAsync([FromBody] LoginModel loginData) { try { if (string.IsNullOrEmpty(loginData.Username)) { throw new ArgumentNullException(nameof(loginData.Username)); } if (string.IsNullOrEmpty(loginData.Password)) { throw new ArgumentNullException(nameof(loginData.Password)); } return(Json(await _authService.Authenticate(loginData))); } catch (Exception ex) { if (ex is ArgumentNullException || ex is ArgumentException) { return(BadRequest(ex)); } if (ex is ApplicationException) { return(UnprocessableEntity(ex)); } return(StatusCode(500, new Exception("Ops, tivemos um problema"))); } }
public async Task <IActionResult> LoginAsync(Authentication model) { try { if (!ModelState.IsValid) { ViewBag.Notification = new SuccessResult(false, "Username and Password are required!"); return(View(model)); } var obj = await _authenticateService.Authenticate(model); SuccessResult sr = null; if (obj.Item1) { var token = obj.Item2; Session.SetString("Token", obj.Item2); TempData["SuccessResultF"] = true; TempData["SuccessResultM"] = "You are logged succssfully!"; return(RedirectToAction("Index", "Home")); } else { sr = new SuccessResult(obj.Item1, obj.Item2); ViewBag.Notification = sr; return(View(model)); } } catch (Exception) { return(View(model)); } }
public IActionResult Authenticate([FromBody] UserAuthData user) { var existingUser = _authenticateService.Authenticate(user.Email, user.Password); if (existingUser == null) { return(BadRequest()); } var secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("ticketwebapiservice@secretkey")); var signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256); var claims = new List <Claim> { new Claim(ClaimTypes.Name, existingUser.Email), new Claim(ClaimTypes.Role, existingUser.Role.ToString()) }; var tokeOptions = new JwtSecurityToken( issuer: "http://localhost:4000", audience: "http://localhost:4000", claims: claims, expires: DateTime.Now.AddDays(7), signingCredentials: signinCredentials ); var tokenString = new JwtSecurityTokenHandler().WriteToken(tokeOptions); return(Ok(new { Token = tokenString, role = existingUser.Role.ToString() })); }
public async Task <IActionResult> Login([FromBody] LoginViewModel creds) { var result = await _authenticateService.Authenticate(creds); if (result) { var secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("superSecretKey@345")); var signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256); var claims = new List <Claim> { new Claim("user", creds.Login), new Claim("role", "Member") }; var tokeOptions = new JwtSecurityToken( claims: claims, expires: DateTime.Now.AddMinutes(5), signingCredentials: signinCredentials ); await HttpContext.SignInAsync(new ClaimsPrincipal(new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme, "user", "role"))); var tokenString = new JwtSecurityTokenHandler().WriteToken(tokeOptions); return(Ok(new { Token = tokenString })); } return(BadRequest("username or password is invalid")); }
public async Task <ActionResult <AuthenticateResponse> > Authenticate(AuthenticateRequest model) { var response = await _accountService.Authenticate(model, ipAddress()); setTokenCookie(response.RefreshToken); return(Ok(response)); }
public UsuarioViewModel Authenticate(string emailcpf, string senha) { senha = Password.MD5Hash(senha); Usuario usuario = _authenticateService.Authenticate(emailcpf, senha); UsuarioViewModel usuarioViewModel = Mapper.Map <UsuarioViewModel>(usuario); return(usuarioViewModel); }
public IActionResult Post([FromBody] Models.Logins model) { var user = _authenticateService.Authenticate(model.UserName, model.PassWord); if (user == null) { return(BadRequest(new { message = "Käyttäjätunnus tai salasana on virheellinen" })); } return(Ok(user)); }
public async Task <ActionResult <IEnumerable <User> > > Login([FromBody] User user) { user = _authService.Authenticate(user.Email, user.Password); if (user == null) { return(BadRequest(new { message = "Bad email and password combination" })); } return(Ok(user)); }
public IActionResult Post([FromBody] User model) { var user = _authenticateService.Authenticate(model.UserName, model.Password); if (user == null) { return(BadRequest(new { message = "Username or password is incorrect" })); } return(Ok(user)); }
public IActionResult Post([FromBody] Student model) { var student = _authenticateService.Authenticate(model.UserName, model.Password); if (student == null) { return BadRequest(new { Message = "invalid username or password" }); } else return Ok(student); }
public IActionResult Post([FromBody] AspNetUserVM vm) { var user = authentication.Authenticate(vm); if (user == null) { return(BadRequest(new { message = "Username and Password is incorrect" })); } return(Ok(user)); }
public IActionResult Post([FromBody] User model) { var user = _authenticateService.Authenticate(model.username, model.password); if (user == null) { return(BadRequest()); } return(Ok(user)); }
public IActionResult Authenticate([FromBody] User user) { var validUser = _authService.Authenticate(user); if (validUser == null) { return(BadRequest()); } return(Ok(validUser)); }
public ActionResult Post([FromBody] User userParams) { var user = _authenticateService.Authenticate(userParams.Name, userParams.Password); if (user == null) { return(BadRequest(new { message = "Username or password is incorrect" })); } return(Ok(new { message = "Successfully authenticating", loggedinUser = user })); }
public async Task <ActionResult <dtoValidateUsercs> > Post([FromBody] DtoUser dtouser) { dtoValidateUsercs user = await _authenticatservice.Authenticate(dtouser.UserName, dtouser.Password); if (user == null) { return(BadRequest(new { message = "Username or Password in Incorrect" })); } return(Ok(user)); }
public UserViewModel Authenticate(string username, string password) { password = Password.MD5Hash(password); User user = _authenticateService.Authenticate(username, password); UserViewModel userViewModel = Mapper.Map <UserViewModel>(user); return(userViewModel); }
public IActionResult Authenticate([FromBody] UserAuthenticate request) { var user = _authenticateService.Authenticate(request.Email, request.Password); if (user == null) { return(NotFound()); } return(Ok(user)); }
public UserResultModel Authenticate(AuthenticateModel model) { var dto = _mapper.Map <AuthenticateDto>(model); var result = _authenticateService.Authenticate(dto); return(new UserResultModel { Token = result.token, User = _mapper.Map <UserModel>(result.user) }); }
[HttpPost] // varsinainen metodi johon frontti ottaa yhteyden public IActionResult Post([FromBody] Models.Login login) { var user = _authenticateService.Authenticate(login.UserName, login.PassWord); // hyödynnetään rajanpinnan palveluita if (user == null) { return(BadRequest(new { message = "Käyttäjätunnus tai salasana on virheellinen" })); } return(Ok(user)); }
public IActionResult Post([FromBody] User user) { var token = _authenticateService.Authenticate(user.Username, user.Password); if (token == null) { return(BadRequest(new { message = "Incorrect credentials" })); } return(Ok(token)); }
public IActionResult Post([FromBody] User model) { User user = null; if (model.Encrypted == null || model.Encrypted == false) { string secret = "This is a sample secret"; user = _authenticateService.Authenticate(HmacConversion.CreateToken(model.ClientId, secret)); } else { user = _authenticateService.Authenticate(model.ClientId); } if (user == null) { return(BadRequest(new { message = "ClientId Invalid." })); } return(Ok(user)); }
public IActionResult Autenticar([FromBody] LoginForm value, [FromServices] IAuthenticateService authenticate) { try { var infoLogin = authenticate.Authenticate(value.login, value.senha); return(Ok(infoLogin)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IActionResult Post([FromBody] User model) { var user = _authenticateService.Authenticate(model.Username, model.Password); if (user == null) { return(BadRequest(new { Message = "invalid username or password" })); } else { return(Ok(user)); } }
public async Task <ActionResult> Login(SignInRequest request) { var response = await _authService.Authenticate(request); if (response.Success) { return(Ok(response.Value)); } else { return(BadRequest(response)); } }
[HttpPost]//Login public IActionResult Post([FromBody] Userdata Model) { var user = _authenticateService.Authenticate(Model); if (user == null) { return(BadRequest(new { message = "Username or Password is incorrect" })); } else { return(Ok(user)); } }
public IActionResult Post(User user) { var result = _authService.Authenticate(user.Username, user.Password); if (result == null) { return(BadRequest(new { message = "username/password is not correct" })); } else { return(Ok(result)); } }
public IActionResult Post([FromBody] Login model) { var student = _authenticateService.Authenticate(model.Email, model.Password); if (student == null) { return(BadRequest(new { Message = "Error your email or password is incorrect" })); } else { return(Ok(student)); } }