public async Task <IActionResult> SignIn(SignInUser user) { if (!ModelState.IsValid) { return(View()); } var appUser = await _userManager.FindByNameAsync(user.Email); if (appUser == null) { ViewBag.error = "The username or password was invalid."; return(PartialView("_SignInPartial")); } var result = await _signInManager.PasswordSignInAsync(appUser, user.Password, user.RememberMe, false); if (result.Succeeded) { return(RedirectToAction(nameof(Index), "Home")); } else if (result.IsLockedOut) { ViewBag.error = "User is locked out. Please try again later."; return(View()); } else { ViewBag.error = "Invalid username or password."; return(View()); } }
public ActionResult NewProfile() { if (Request.Cookies["SignInCookie"] != null) { string[] cookie = Request.Cookies["SignInCookie"].Value.Split(','); int userId = int.Parse(cookie[0]); User user = UsersRepository.GetUser(userId); SignInUser signInUser = new SignInUser() { FirstName = user.FirstName, LastName = user.LastName, BirthDate = user.BirthDate, Email = user.Email, UserName = user.UserName, Password = user.Password, VerificationPassword = user.Password }; LoginSignModel loginSignModel = new LoginSignModel() { SignInUser = signInUser }; return(View(loginSignModel)); } return(RedirectToAction("SignIn")); }
public ContentResult Login(SignInUser model) { var mail = con.SignInUser.SingleOrDefault(x => x.Email.Equals(model.Email)); var pass = con.SignInUser.SingleOrDefault(x => x.Email.Equals(model.Email) & x.Password.Equals(model.Password)); if (mail == null) { var res = new ContentResult { Content = "NoUser", StatusCode = 0 }; return(res); } else if (pass == null) { var res = new ContentResult { Content = "NoPass", StatusCode = 1 }; return(res); } else { var res = new ContentResult { Content = pass.Id.ToString(), StatusCode = 2 }; return(res); } }
/// <summary> /// 刪除某筆回覆 /// </summary> /// <param name="model">要刪除的回覆entity</param> public void DeleteReply(ReplyViewModel model) { _replyRepo.Delete(_conn, model.Id); if (model.CreateUserId == SignInUser.User.Id) { SignInUser.AdjustReplyCnt(-1); } }
protected void Page_Load(object sender, EventArgs e) { //SessionHelper.Dastgah.Refresh(7010028);6855Y6B7 //Response.Redirect("~/InsuredAgentOrg/Default.aspx", false); SignInUser.Focus(); SignInUser.Attributes.Add("OnKeyPress", "javascript:return CheckNumeric(event.keyCode, event.which);"); ImgHyp.NavigateUrl = Request.Url.ToString().Contains("?") ? Request.Url.ToString().Replace("?I=1", "") : Request.Url.ToString(); TextBox_number.Attributes.Add("OnKeyPress", "javascript:return CheckNumeric(event.keyCode, event.which);"); }
/// <summary> /// 新增文章 /// </summary> /// <param name="model">The model.</param> public void CreatePost(PostViewModel model) { var entity = ConvertToEntity(model); entity.CreateUserId = SignInUser.User.Id; entity.UpdateUserId = SignInUser.User.Id; _postRepo.Create(_conn, entity); SignInUser.AdjustPostCnt(1); }
public async Task SignIn(SignInUser user) { await EnsureInitialized().ConfigureAwait(false); var credential = await _jsRuntime .InvokeAsync <FirebaseUser>("firebaseauth.signIn", user.Username, user.Password) .ConfigureAwait(false); Console.WriteLine($"User {credential.Email} signed in."); }
/// <summary> /// 新增回覆 /// </summary> /// <param name="model">回覆entity</param> /// <returns></returns> public int CreateReply(ReplyViewModel model) { var entity = ConvertToEntity(model); entity.CreateUserId = SignInUser.User.Id; entity.UpdateUserId = SignInUser.User.Id; var id = _replyRepo.Create(_conn, entity); SignInUser.AdjustReplyCnt(1); return(id); }
public void SignOut([FromBody] SignInUser model) { var user = new ApplicationUser { UserName = model.UserName }; _signInManager.SignOutAsync(); //throw new ApplicationException("UNKNOWN_ERROR"); }
public ActionResult Update(int id, MemberUpdateViewModel model) { var user = _memberService.GetUser(id); if (ModelState.IsValid.Equals(false)) { model.Pic = user.Pic; return(View(model)); } // Update Table Password var newPassword = model.Password; if (string.IsNullOrEmpty(newPassword).Equals(false)) { var newPassEntity = _memberService.ConvertToPassEntity(user.Id, user.Guid, newPassword); // 管理者可以強制變更密碼 if (SignInUser.User.IsAdmin.Equals(false)) { var isSamePassword = _memberService.CheckIsHistroyPassword(user.Id, newPassEntity.HashPw); if (isSamePassword) { ModelState.AddModelError("HistroyPassword", "新密碼不可跟使用過的舊密碼相同。"); model.Password = string.Empty; return(View(model)); } } _memberService.CreatePassword(newPassEntity); } // 大頭照 var fileName = _memberService.SaveMemberPic(model.File, Server.MapPath(FileUploadPath)); if (string.IsNullOrEmpty(fileName).Equals(false)) { user.Pic = $"{FileUploadPath}/{fileName}"; } // Update Table User user.Name = model.Name; _memberService.UpdateUser(user); // 修改自己的資料完畢之後也要更新Session if (SignInUser.User.Id == id) { var artCnt = _memberService.GetUserArticleCount(user.Id); SignInUser.UserLogin(true, user, artCnt); } return(RedirectToAction(model.BackAction, model.BackController, new { page = model.BackPage })); }
public bool SignIn(SignInUser user) { var validUser = _ctx.KhachHangs.FirstOrDefault(kh => kh.UserName == user.UserName); if (validUser == null) { return(false); } var hash = Utility.GetMd5Hash(user.Password); return(validUser.Password == hash); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { SignInUser signModel = (SignInUser)validationContext.ObjectInstance; bool Valid = UsersRepository.IsUserNameValid(signModel.UserName); if (Valid) { return(ValidationResult.Success); } else { return(new ValidationResult("User name is already in use! choose diffrent")); } }
public IViewComponentResult Invoke(string viewName) { object model = null; if(viewName == "SignIn") { model = new SignInUser(); } else { model = new User(); } return View(viewName, model); }
public ActionResult SignInApp([FromBody] SignInUser signInUser) { UserAccount user = dbUnit.UserAccountRepository.FindByCredential(signInUser.Login, signInUser.Password); if (user == null) { return(BadRequest(HttpResponseMessages.SignInFailed)); } int schoolId = user.Role == ApiConfig.ROLE_ADMIN ? dbUnit.SchoolRepository.FindByUserId(user.Id).Id : dbUnit.PersonalDataRepository.FindByUserId(user.Id).SchoolId; Request.HttpContext.SignInAsync(ApiConfig.COOKIE, jwtService.GetClaimsForCookies(user.Id, schoolId, user.Role, user.Email)); return(Ok(HttpResponseMessages.SignInSuccess)); }
private SignInUser GetSignInUser(DataTable dt) { if (dt.Rows.Count == 0) { return(null); } var dr = dt.Rows[0]; var user = new SignInUser { Id = (int)dr["id"], Email = (string)dr["email"], FullName = (string)dr["full_name"], Address = (dr["address"]).GetType() == typeof(DBNull)? null: dr["address"].ToString() }; return(user); }
public ActionResult SignIn(SignInUser su) { if (ModelState.IsValid) { User u = uRepo.getByEmailnPass(su.Email, su.Password); if (u == null) { Session["EmailnPass"] = "******"; return(View("SignIn", su)); } Session["EmailnPass"] = "******"; Session["LoggedIn"] = "true"; Session["UserId"] = u.id; Session["RollId"] = u.RoleId; return(RedirectToAction("Index", "Feed")); } return(View("SignIn", su)); }
public async Task <IActionResult> Login([FromBody] SignInUser command) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = await _authService.LoginAsync(command.Email, command.Password); if (user == null) { return(Unauthorized()); } var token = new TokenDTO { Token = await GenerateToken(user, _jwtSettings) }; return(Ok(token)); }
public ActionResult SignIn(SignInUser user) { if (!ModelState.IsValid) { return(View()); } if (_userMgr.SignIn(user)) { Session["user"] = user.UserName; if (TempData.ContainsKey("previousUrl")) { return(Redirect(TempData["previousUrl"].ToString())); } return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("unavailable", "The user name or email address has already existed!"); return(View()); }
/// <summary> /// 新增網站會員 /// </summary> /// <param name="model">The model.</param> /// <param name="path">存放大頭照的實體路徑</param> public void CreateUser(MemberCreateViewModel model, string path) { using (var tranScope = new TransactionScope()) { // Table User var fileName = SaveMemberPic(model.File, path); var user = ConvertToUserEntity(model, $"{FileUploadPath}/{fileName}"); user.Id = _userRepo.Create(_conn, user); var userVm = ConvertToUserViewModel(user); // Table Password var password = ConvertToPassEntity(user.Id, user.Guid, model.Password); CreatePassword(password); // 註冊完直接給他登入-因為是新會員,所以文章count直接給預設0即可 SignInUser.UserLogin(true, userVm, new UserArticleCount()); tranScope.Complete(); } }
public IActionResult Register(SignInUser signInUser) { if (ModelState.IsValid) { try { RSAEncryption encryption = new RSAEncryption(); signInUser.Pwd = System.Text.Encoding.UTF8.GetString(encryption.Encrypt(signInUser.Pwd)); authRepository.Register(signInUser); return(RedirectToAction("Login")); } catch (Exception) { return(View("Error")); } } return(View(signInUser)); }
// GET: Product public ActionResult Detail(int?id) { if (id == null) { return(HttpNotFound()); } var product = ProductsRepository.GetProduct(id.Value); var user = UsersRepository.GetUser(product.OwnerId); var signInUser = new SignInUser() { FirstName = user.FirstName, LastName = user.LastName, Email = user.Email }; LoginSignModel loginSignModel = new LoginSignModel() { Product = product, SignInUser = signInUser }; return(View(loginSignModel)); }
public ActionResult SignInAsync([FromBody] SignInUser signInUser) { var userDb = _userRepo.GetOneByExpression(x => x.Username == signInUser.Username); if (!userDb.Success || userDb.Data == null) { return(BadRequest("Wrong username")); } if (!Hash.Validate(signInUser.Password, userDb.Data.PasswordHash)) { return(BadRequest("Wrong password")); } var identity = _jwtService.GetIdentityFromUser(userDb.Data); var token = _jwtService.GenerateToken(identity.Claims); return(Ok(new { Token = token, User = userDb.Data })); }
public ActionResult Inscription(SignInUser u) { if (ModelState.IsValid) { if (userRepository.GetAll().Select(x => x.Email).FirstOrDefault() == u.Email) { //userRepository.Create(u.) return(RedirectToAction("Index")); } else { ViewBag.ErrorMessage = "Adresse Email déjà utilisé"; return(View(u)); } } else { return(View(u)); } }
public async Task <IActionResult> SignIn([FromBody] SignInUser model) { var user = await _userManager.FindByNameAsync(model.UserName); var authorized = await _userManager.CheckPasswordAsync(user, model.Password); if (authorized) { await _signInManager.SignInAsync(user, false, "jwt"); var token = GenerateJwtToken(model.UserName, user); var result = new { token = token }; return(Ok(result)); } else { var errors = new List <string>(); errors.Add("Incorrect Password"); return(Ok(new { errors = errors })); } }
public async Task <UserResponse> SingIn([FromBody] SignInUser signInUser, CancellationToken cancellationToken) { User user = await userManager.FindByEmailAsync(signInUser.Email); if (user is null) { throw new RestException(HttpStatusCode.Unauthorized.ToString()); } var result = await signInManager.CheckPasswordSignInAsync(user, signInUser.Password, false); if (result.Succeeded) { return(new UserResponse { Token = jwtGenerator.CreateToken(user), Id = user.Id }); } throw new RestException(HttpStatusCode.Unauthorized.ToString()); }
public ActionResult Login(MemberLoginViewModel model) { ViewBag.Title = "會員登入"; if (!ModelState.IsValid) { return(View(model)); } var loginResult = _memberService.CheckUserPassword(model.Account, model.Password); if (loginResult.Auth.Equals(false)) { ModelState.AddModelError("LoginError", "帳號或密碼錯誤"); return(View(model)); } var artCnt = _memberService.GetUserArticleCount(loginResult.User.Id); SignInUser.UserLogin(true, loginResult.User, artCnt); return(RedirectToAction("Index", "Post")); }
public async Task <ContentResult> SignIn(SignInUser model) { var add = await con.AddAsync(model); var res = await con.SaveChangesAsync(); if (res == 1) { return new ContentResult { StatusCode = 2 } } ; else { return new ContentResult { StatusCode = 1 } }; } }
/// <summary> /// 刪除文章及回覆 /// </summary> /// <param name="id">The identifier.</param> public void DeletePostAndReply(int id) { using (var transScope = new TransactionScope()) { using (var connection = _connFactory.GetConnection()) { // Delete Post _postRepo.Delete(connection, id); // Delete Reply _replyRepo.DeleteByPostId(connection, id); } transScope.Complete(); } // 刪除文章、回復,有可能刪除到管理者或是其他人的資料,因此直接重新刷新目前User的文章數量資訊 var artCnt = new UserArticleCount() { PostCount = _postRepo.GetPostCountByUserId(_conn, SignInUser.User.Id), ReplyCount = _replyRepo.GetReplyCountByUserId(_conn, SignInUser.User.Id) }; SignInUser.SetArticleCount(artCnt); }
public UpdatePermissionsForRoleCommandValidator(DatabaseContext databaseContext, SignInUser signInUser) { this.databaseContext = databaseContext; RuleFor(x => x.RoleId).NotEmpty().NotNull().Must(Test); RuleFor(x => x.PermissionIds).NotEmpty().ForEach(x => x.NotEmpty().NotNull()); }
public async Task <ActionResult> SignInAsync([FromBody] SignInUser signInUser) { return(Ok(await _requestService.PostFromDockerServiceAsync(RequestService.authservice, RequestService.authservicePort, "/auth/sign-in", signInUser))); }
public IActionResult SignIn(SignInUser signInUser) { if (ModelState.IsValid) { using (var dataContext = new RSSReaderDataContext()) { var loggedInUser = dataContext.Users.FirstOrDefault(x => x.Email == signInUser.Email && x.Password == signInUser.Password); if (loggedInUser != null) { var user = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Email, loggedInUser.Email), new Claim(ClaimTypes.Name , loggedInUser.Name), new Claim(ClaimTypes.NameIdentifier, loggedInUser.Id.ToString()) }, CookieAuthenticationDefaults.AuthenticationScheme)); Context.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, user); return Redirect("~/Home/Index"); } else { ModelState.AddModelError("", "Login failed. Please check your username / password"); return View("SignIn"); } } } else { ModelState.AddModelError("", "Please fill all the required fields."); return View("SignIn"); } }
public IActionResult Login(SignInUser model) { return(Ok(LoginService.Login(model))); }