public ActionResult LogIn(UserLoginView ULV, string returnUrl) { if (ModelState.IsValid) { UserManager UM = new UserManager(); string password = UM.GetUserPassword(ULV.NIK); if (string.IsNullOrEmpty(password)) { ModelState.AddModelError("", "NIK atau password salah."); } else { if (UM.IsPasswordMatch(ULV.NIK, ULV.Password)) // memanggil fungsi cek password hashed Bcrypt { FormsAuthentication.SetAuthCookie(ULV.NIK, false); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Password yang dimasukkan salah."); } } } // If we got this far, something failed, redisplay form return(View(ULV)); }
public ActionResult Login(UserLoginView model, string returnUrl) { if (ModelState.IsValid) { UserManager userManager = new UserManager(); string password = userManager.GetUserPassword(model.LoginName); if (string.IsNullOrEmpty(password)) { ModelState.AddModelError("", "The user login or password provided is incorrect."); } else { if (model.Password.Equals(password)) { FormsAuthentication.SetAuthCookie(model.LoginName, false); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "The password provided is incorrect."); } } } return(View(model)); }
public ActionResult LogIn(UserLoginView ULV, string returnUrl) { if (ModelState.IsValid) { UserManager UM = new UserManager(); string password = UM.GetUserPassword(ULV.LoginName); if (string.IsNullOrEmpty(password)) { ModelState.AddModelError("", "The user login or password provided is incorrect."); } else { if (ULV.Password.Equals(password)) { FormsAuthentication.SetAuthCookie(ULV.LoginName, false); return(RedirectToAction("Welcome", "Home")); } else { ModelState.AddModelError("", "The password provided is incorrect."); } } } // If we got this far, something failed, redisplay form return(View(ULV)); }
public IActionResult Token([FromBody] UserLoginView model) { if (!ModelState.IsValid) { return(BadRequest("Could not create token")); } var dbUser = _userService.Login(model); if (!dbUser) { return(Unauthorized(new Exception("Λάθος username ή password"))); } var claims = new List <Claim>(); claims.Add(new Claim("username", "Administrator")); claims.Add(new Claim("role", "admin")); var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"])); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var token = new JwtSecurityToken(_config["Jwt:Issuer"], _config["Jwt:Issuer"], claims, expires: DateTime.UtcNow.AddHours(24), signingCredentials: creds); return(Ok(new { token = new JwtSecurityTokenHandler().WriteToken(token) })); }
public async Task <ActionResult> Login(UserLoginView userLogin) { var command = new UserLoginCommand(userLogin.Email, userLogin.Password); var result = await _mediator.SendCommand <UserLoginCommand, UserLoginResponse>(command).ConfigureAwait(false); return(CustomResponse <UserLoginResponse>(result)); }
public ActionResult LogIn(UserLoginView ULV, string returnUrl) { if (ModelState.IsValid) { UserManager UM = new UserManager(); var user = UM.GetUserFromDatabase(ULV.LoginName); string password = UM.GetUserPassword(ULV.LoginName); if (string.IsNullOrEmpty(password)) { ModelState.AddModelError("", "The user login or password provided is incorrect."); } else { if (ULV.Password.Equals(password)) { FormsAuthentication.SetAuthCookie(ULV.LoginName, false); return(RedirectToAction("Index", "Home", new { Id = user.SYSUserID })); } else { ModelState.AddModelError("", "The password provided is incorrect."); } } } return(View(ULV)); }
public async Task <IActionResult> Token([FromBody] UserLoginView model) { if (!ModelState.IsValid) { return(BadRequest("Could not create token")); } var dbUser = await _userService.Login(model); if (dbUser == null) { return(Unauthorized(new Exception("Λάθος username ή password"))); } var claims = new List <Claim>(); claims.Add(new Claim("username", dbUser.Username)); claims.Add(new Claim("email", dbUser.Email)); claims.Add(new Claim("title", dbUser.Title)); claims.Add(new Claim("userid", dbUser.Id)); claims.Add(new Claim("role", dbUser.Role.ToString())); claims.Add(new Claim("sites", string.Join(';', dbUser.Sites))); var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"])); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var token = new JwtSecurityToken(_config["Jwt:Issuer"], _config["Jwt:Issuer"], claims, expires: DateTime.UtcNow.AddHours(8), signingCredentials: creds); return(Ok(new { token = new JwtSecurityTokenHandler().WriteToken(token) })); }
public ActionResult LogIn(UserLoginView ulv, string returnUrl) { if (ModelState.IsValid) { UserManager um = new UserManager(); string password = um.GetUserPassword(ulv.LoginName); if (string.IsNullOrEmpty(password)) { ModelState.AddModelError("", "The User Login or Password Provided is Incorrect"); } else { if (ulv.Password.Equals(password)) { FormsAuthentication.SetAuthCookie(ulv.LoginName, false); return(RedirectToAction("Welcome", "Home")); } else { ModelState.AddModelError("", "The Password Provided is Incorrect"); } } } return(View(ulv)); }
public ActionResult Login([Bind(Include = "Username, Password")] UserLoginView userLoginView) { if (ModelState.IsValid) { var usr = db.Users.Where(u => u.UserName == userLoginView.UserName).FirstOrDefault(); if (usr != null) { if (usr.Password == userLoginView.Password) { var session = new UserSession() { UserID = usr.UserID, UserName = usr.UserName, }; this.Session["ValidateSession"] = session; return(RedirectToAction("LoggedIn")); } else { ViewBag.InvalidPassword = true; userLoginView.Password = null; return(View("Login")); } } return(RedirectToAction("Login")); } return(View(userLoginView)); }
public ActionResult Login(UserLoginView loginView) { if (ModelState.IsValid) { User userFound = DB.Users.Where(u => u.UserName == loginView.UserName).FirstOrDefault(); if (userFound == null) { ModelState.AddModelError("UserName", "This username does not exist"); return View(); } else { if (userFound.Password != loginView.Password) { ModelState.AddModelError("password", "Wrong password"); return View(); } } OnlineUsers.AddSessionUser(userFound); } else return View(); return RedirectToAction("Index", "Home"); }
public IHttpResponse Login(UserLoginView view) { if (!this.userService.Validate(view)) { return(BadRequestErrorWithView("Invalid username or password!")); } var user = this.userService.GetUser(view.Username); var mvcUser = new MvcUserInfo { Username = user.Username, Role = user.Role.ToString(), Info = user.Email }; var cookieContent = this.UserCookieService.GetUserCookie(mvcUser); var cookie = new HttpCookie(".auth-cakes", cookieContent, 7) { HttpOnly = true }; this.Response.Cookies.Add(cookie); return(this.Redirect("/")); }
public async Task <UserProfile> LoginUser(UserLoginView loginParam) { UserProfile userProfile = new UserProfile(); var uriPost = new Uri(hostUrl + "api/login"); try { var jsonData = JsonConvert.SerializeObject(loginParam); var content = new StringContent(jsonData, Encoding.UTF8, "application/json"); HttpResponseMessage response = await _client.PostAsync(uriPost, content); if (!response.IsSuccessStatusCode) { throw new Exception($"Gagal menambah data: {response.StatusCode}"); } else { var resContent = await response.Content.ReadAsStringAsync(); userProfile = JsonConvert.DeserializeObject <UserProfile>(resContent); return(userProfile); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public ActionResult Login(UserLoginView userLogin) { if (ModelState.IsValid) { string passwordEncrypted = Crypto.crypto.GenerateSHA256String(userLogin.Password); var v = db.Utilizador.Where(u => u.nome_utilizador == userLogin.Username && u.senha_utilizador == passwordEncrypted); if (v != null) { //Criar objeto que passe toda informação session try { Session["username"] = v.First().nome_utilizador; Session["Id"] = v.First().id_utilizador; Session["Tipo"] = v.First().id_tipo; FormsAuthentication.SetAuthCookie(v.First().nome_utilizador, false); } catch (InvalidOperationException e) { TempData["errorMessage"] = "Email e/ou password erradas! Tente novamente"; return(View("Error", new HandleErrorInfo(new Exception("Email e/ou password erradas! Tente novamente"), "Utilizadors", "Login"))); } return(RedirectToAction("Index", "Relatorios")); } } return(View()); }
public async Task LoginUser_ShouldRetunLoginFail(CommandResult <UserLoginResponse> result) { //Arrange var request = new UserLoginView(); request.Email = "*****@*****.**"; request.Password = "******"; result.Payload = new UserLoginResponse(); result.ValidationResult.Errors.Add(new ValidationFailure(string.Empty, "Invalid request")); _mediatorHandler.Setup(s => s.SendCommand <UserLoginCommand, UserLoginResponse>(It.IsAny <UserLoginCommand>())).ReturnsAsync(result); _sut = new AuthController(_mediatorHandler.Object); //Act var response = await _sut.Login(request); //Assert var responseAssert = new BadRequestObjectResultMap(response); var expectedErrors = new List <string> { "Invalid request" }; responseAssert.IsInvalidRequest(expectedErrors); }
public ActionResult LogIn(UserLoginView ULV, string returnUrl) { if (ModelState.IsValid) { UserManager UM = new UserManager(); string password = UM.GetUserPassword(ULV.LoginName); if (string.IsNullOrEmpty(password)) { ModelState.AddModelError("", "Username atau Password salah!"); } else { if (ULV.Password.Equals(password)) { FormsAuthentication.SetAuthCookie(ULV.LoginName, false); return(RedirectToAction("Welcome", "Home")); } else { ModelState.AddModelError("", "Password Salah!"); } } } return(View(ULV)); }
public object View() { return(_userLoginView ?? (_userLoginView = new UserLoginView() { DataContext = this })); }
public ActionResult LogIn(UserLoginView ULV, string returnUrl) { CustomMembershipProvider cs = new CustomMembershipProvider(); if (ModelState.IsValid && cs.ValidateUser(ULV.LoginName, ULV.Password)) { UserManager UM = new UserManager(); string password = UM.GetUserPassword(ULV.LoginName); if (string.IsNullOrEmpty(password)) { ModelState.AddModelError("", "The user login or password provided is incorrect."); } else { if (Crypto.VerifyHashedPassword(password, ULV.Password)) { FormsAuthentication.SetAuthCookie(ULV.LoginName, false); return(RedirectToAction("Welcome", "Home")); } else { ModelState.AddModelError("", "The password provided is incorrect."); } } string[] roless = UM.GetRolesForUser(ULV.LoginName); } // If we got this far, something failed, redisplay form return(View(ULV)); }
public ActionResult forgotPassword(UserLoginView user) { UserManager mgr = new UserManager(); mgr.updateUserDetails(user.UHCLEmail, user.confirmPassword); TempData["Message"] = "Password updated successfully."; return RedirectToAction("LogIn", "Account"); }
public async Task <UserView> LoginAsync(UserLoginView userLoginView) { UserView userView = null; var client = new RestClient(_loginServiceUrl); var request = new RestRequest("api/login", Method.POST); request.AddHeader("content-type", "application/json"); request.AddHeader("api-version", "1"); request.AddParameter("application/json", JsonConvert.SerializeObject(userLoginView).ToString(), ParameterType.RequestBody); //client.ExecuteAsync(request, response => //{ // var result = response; //}); var response = await client.ExecuteAsync <object>(request); dynamic data = JsonConvert.DeserializeObject(response.Content); if ((bool)data.status) { string tempJson = JsonConvert.SerializeObject(data.result); userView = JsonConvert.DeserializeObject <UserView>(tempJson); Token = userView.Jwt.Token; } return(userView); }
//[AllowAnonymous] public IActionResult UserLogin(string returnUrl = null) { if (_currentUser.CurrentUser.UserRoleName.FirstOrDefault() == "User" && _currentUser.CurrentUser.Activation == true) { return(RedirectToAction("profile", "Profile")); } if (_currentUser.CurrentUser != null) { if (_currentUser.CurrentUser.UserRoleName.FirstOrDefault() != "Guest") { if (Url.IsLocalUrl(returnUrl)) { return(Redirect(returnUrl)); } } } if (_currentUser.CurrentUser.UserRoleName.FirstOrDefault() == UserRoleName.TicketingUser && _currentUser.CurrentUser.Activation == true) { return(RedirectToAction("TicketingView", "Home")); } // else // return RedirectToAction("Index", "Dashboard", new { Area = "Admin" }); this.ViewData["ReturnUrl"] = returnUrl; UserLoginView model = new UserLoginView(); model.returnUrl = returnUrl; return(View(model)); }
public async Task <UserView> GetSystemUserAsync(UserLoginView userLoginView) { UserView SystemUser = null; SystemUser = await this.LoginAsync(userLoginView); return(SystemUser); }
public bool Login(UserLoginView user) { if (user.Password == "geakmh" && user.Username == "admin") { return(true); } return(false); }
public void LogoutToView() { DialogHelper.Context.Closing += (o, e) => { UserLoginView view = new UserLoginView(); view.Show(); }; // Close current window DialogHelper.Context.Close(); }
public async Task <CommonApiResponse <UserView> > Post([FromBody] UserLoginView userLoginView) { Client identityClient = new Client(Config.IdentityServiceBaseUrl); UserView userView = await identityClient.LoginAsync(userLoginView); if (userView == null) { return(CommonApiResponse <UserView> .Create(Response, System.Net.HttpStatusCode.BadRequest, false, null, "Kullanıcı bilgileri geçersiz.")); } return(CommonApiResponse <UserView> .Create(Response, System.Net.HttpStatusCode.OK, true, userView, "")); }
public UserView Login(UserLoginView user) { bool isValidLogin = _customerService.CheckLogin(user); if (isValidLogin) { return(_customerService.getUser(user.Email)); } return(null); }
public bool IsAdmin(UserLoginView userLogin) { foreach (var item in dal.GetUserLoginList()) { if (userLogin.UserID == item.UserID) { return(item.IsAdmin); } } return(false); }
private void DisplayUserLoginView() { PageTitle.Text = "registration"; button.Visibility = Visibility.Collapsed; var userLoginView = new UserLoginView { UserName = "******" }; userLoginView.Login += userLoginView_Login; ActiveView = userLoginView; }
public JsonResult Index(UserLoginView userToCheck) { //User.Identity.Name отсюда доставешь инфу кто залогинен и показываешь ему инфу основанную на этом if (!ModelState.IsValid) { return(new JsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { IsSuccess = false } }); } //using (RegistrationService registry = new RegistrationService(SignInManager)) //{ // try // { RegistrationService registry = new RegistrationService(SignInManager); var existedUser = registry.UserValid(userToCheck.Email, userToCheck.Password); if (existedUser != null) { SignInManager.PasswordSignIn(existedUser.UserName, userToCheck.Password, false, false); //SignInManager.SignOut(); var asd = User.Identity.Name; return(new JsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { IsSuccess = true } }); } ; //} //catch //{ // return new JsonResult() // { // JsonRequestBehavior = JsonRequestBehavior.AllowGet, // Data = new { IsSuccess = false} // }; //return View("Querylist", registry.UserQueries(userToCheck.Id)); //} return(new JsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { IsSuccess = false } }); //} }
public ActionResult FacebookCallback(string code) { var fb = new FacebookClient(); try { dynamic result = fb.Post("oauth/access_token", new { client_id = "148384642407735", client_secret = "25b570ffac6aae99ab8729f63ea3c757", redirect_uri = RediredtUri.AbsoluteUri, code = code }); var accessToken = result.access_token; //Session["AccessToken"] = accessToken; fb.AccessToken = accessToken; // to get all user data from url dynamic me = fb.Get("me?fields=link,first_name,currency,last_name,email,gender,locale,timezone,verified,picture,age_range"); string email = me.email; TempData["email"] = me.email; TempData["first_name"] = me.first_name; TempData["lastname"] = me.last_name; //TempData["picture"] = me.picture.data.url; //FormsAuthentication.SetAuthCookie(email, false); #region chick if User email is exist or not var user = _userRepository.GetUserByEmail(email); if (user != null) { UserLoginView userLogIn = new UserLoginView() { Email = email, }; return(View("UserLogin", userLogIn)); } else { UserRegisterModel userRegister = new UserRegisterModel() { Email = me.email, Name = me.first_name, }; return(View("RegisterUser", userRegister)); } #endregion } catch { return(RedirectToAction("Index", "Home")); } }
public bool Validate(UserLoginView view) { if (!Validate(view.Username, view.Password)) { return(false); } var hashPassword = this.hashService.Hash(view.Password); return(this.cotnext.Users .Any(u => u.Username == view.Username && u.Password == hashPassword)); }
public async Task <IActionResult> Login([FromBody] UserLoginView view) { try { var user = await _service.Login(view.Email, view.Password); return(Ok(user.ToPrivateDto())); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult LogIn(UserLoginView ULV, string returnUrl) { if (ModelState.IsValid) { UserRepository UM = new UserRepository(); var CurrUSer = UM.AuthenticateUser(ULV.Email, ULV.Password); if ((bool)CurrUSer.IsLoginSuccess) { FormsAuthentication.SetAuthCookie(ULV.Email, false); var role = CurrUSer.Role; return RedirectToAction("DashBoard", role); } else if (!(bool)CurrUSer.IsLoginSuccess) { ModelState.AddModelError("", "The user login or password provided is incorrect."); return View(ULV); } else return View(ULV); } else return View(); }