public ActionResult Login(LoginViewModel login) { if (ModelState.IsValid) { string password = PasswordProcess.GetHashPassword(login.密碼); 客戶資料 客戶資料 = 客戶資料repo .Where(p => p.帳號 == login.帳號 && p.密碼 == password) .FirstOrDefault(); if (客戶資料 != null) { Session["Login"] = "******"; return(RedirectToAction("Edit", "Login", new { id = 客戶資料.客戶Id })); } if (客戶資料 == null && login.帳號 == "Admin" && login.密碼 == "123qweasd") { Session["Login"] = "******"; return(RedirectToAction("Index", "客戶清單")); } } return(View()); }
public ActionResult Edit([Bind(Include = "客戶Id,客戶分類,客戶名稱,統一編號,電話,傳真,地址,Email,帳號,密碼,CreateDate,Active")] 客戶資料 客戶資料) { if (ModelState.IsValid) { if (客戶資料.密碼 == null) { 客戶資料.密碼 = 客戶資料repo .Where(p => p.客戶Id == 客戶資料.客戶Id) .Select(p => p.密碼) .FirstOrDefault(); } else { 客戶資料.密碼 = PasswordProcess.GetHashPassword(客戶資料.密碼); } var db = 客戶資料repo.UnitOfWork.Context; db.Entry(客戶資料).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.客戶分類 = new SelectList(客戶類型repo.All(), "客戶分類", "客戶分類", 客戶資料.客戶分類); return(View(客戶資料)); }
public JsonResult GetNewPassword() { string password = PasswordProcess.GenerateRandomPassword(); return(Json(new { Password = password })); }
public async Task <JsonResult> Register(RegisterViewModel model) { try { var user = new User(); #region Email Validity Check if (EmailProcess.IsValidEmail(model.Email) == false) { return(Json(new JsonMessage { HataMi = true, Baslik = "İşlem Başarısız", Mesaj = "Geçersiz E-Mail Adresi. Lütfen Kontrol Edin." })); } #endregion #region Password Validity Check var checkPassword = PasswordProcess.IsValidPassword(model.Password); if (checkPassword != null) { return(Json(new JsonMessage { HataMi = true, Baslik = "İşlem Başarısız", Mesaj = checkPassword })); } if (model.Password != model.ReTypePassword) { return(Json(new JsonMessage { HataMi = true, Baslik = "İşlem Başarısız", Mesaj = "Lütfen Parola Bilgilerinizi Kontrol Edin." })); } #endregion #region Default Picture Url Settings string defautPictureUrl = null; if (model.Gender == Constants.Gender.Male) { defautPictureUrl = Constants.DefaultPictureUrl.DefaultPictureUrlMale; } if (model.Gender == Constants.Gender.Female) { defautPictureUrl = Constants.DefaultPictureUrl.DefaultPictureUrlFemale; } #endregion #region Default User Type Settings var studentUserType = await _userTypeService.SingleOrDefaultAsync(x => x.Code == UserTypes.Student.GetHashCode()); #endregion #region User Sistemde Var Mı Kontrolü user = await _userService.SingleOrDefaultAsync(x => x.Email == model.Email && x.Name.ToLower() == model.UserName.ToLower() && x.Surname.ToLower() == model.UserSurname.ToLower() && x.IsDeleted == false); if (user != null) { return(Json(new JsonMessage { HataMi = true, Baslik = "İşlem Başarısız", Mesaj = "Eklemek istediğiniz özelliklere sahip kullanıcı sistemde zaten mevcut." })); } #endregion #region Kayıt İşlemi user = new User { Name = model.UserName, Surname = model.UserSurname, Email = model.Email, Password = PasswordProcess.HesaplaSHA256(model.Password), RegisterDate = DateTime.Now, IsDeleted = false, UserTypeId = studentUserType.Id, PictureUrl = defautPictureUrl, Gender = model.Gender, }; await _userService.AddAsync(user); #endregion return(Json(new JsonMessage { HataMi = false, Baslik = "İşlem Başarılı", Mesaj = "Kayıt İşleminiz Başarıyla Gerçekleşti." })); } catch (Exception) { return(Json(new JsonMessage { HataMi = true, Baslik = "İşlem Başarısız", Mesaj = "İşlem Başarısız. Yöneticinize Başvurun." })); } }
public async Task <IActionResult> UserOperations(UserModel model) { try { var OperationType = _session.GetString("OperationType"); var user = new User(); string mesaj = ""; //Kayıt olan kullanıcının cinsyetine göre otomatik avatar resmi ataması. #region Default Picture Settings var pictureUrl = model.Gender == Constants.Gender.Male ? Constants.DefaultPictureUrl.DefaultPictureUrlMale : Constants.DefaultPictureUrl.DefaultPictureUrlFemale; #endregion //Yeni Kayıt İse ekle if (OperationType == Constants.OperationType.Insert) { #region User Sistemde Var Mı Kontrolü user = await _userService.SingleOrDefaultAsync(x => x.Email == model.Email && x.Name.ToLower() == model.Name.ToLower() && x.Surname.ToLower() == model.Surname.ToLower() && x.IsDeleted == false); if (user != null) { return(Json(new JsonMessage { HataMi = true, Baslik = "İşlem Başarısız", Mesaj = "Eklemek istediğiniz özelliklere sahip kullanıcı sistemde zaten mevcut." })); } #endregion #region User Ekle user = new User { Name = model.Name, Surname = model.Surname, Gender = model.Gender, Email = model.Email, UserTypeId = model.UserTypeId, PictureUrl = pictureUrl, IsDeleted = false, RegisterDate = DateTime.Now, Password = PasswordProcess.HesaplaSHA256(model.Password), }; await _userService.AddAsync(user); mesaj = "Yeni Kullanıcı Başarıyle Eklendi."; #endregion #region Send Mail string body = "Sisteme hoşgeldiniz. " + user.Email + " Şifreniz: " + model.Password; await _mailer.SendEmailAsync(/*"*****@*****.**"*/ user.Email, "Test", body); #endregion } //Güncelleme ise if (OperationType == Constants.OperationType.Update) { #region User Update user = await _userService.GetByIdAsync(model.Id); user.Name = model.Name; user.Surname = model.Surname; user.Gender = model.Gender; user.PictureUrl = pictureUrl; user.Email = model.Email; user.UserTypeId = model.UserTypeId; _userService.Update(user); mesaj = "Yeni Kullanıcı Başarıyle Güncellendi."; #endregion } return(Json(new JsonMessage { HataMi = false, Baslik = "İşlem Başarılı", Mesaj = mesaj })); } catch (Exception ex) { return(Json(new JsonMessage { HataMi = true, Baslik = "İşlem Başarısız", Mesaj = "Hata Oluştu." })); } }
public async Task <JsonResult> UserLogin(LoginViewModel model) { #region Email Validity Check if (EmailProcess.IsValidEmail(model.UserMail) == false) { return(Json(new JsonMessage { HataMi = true, Baslik = "İşlem Başarısız", Mesaj = "Geçersiz E-Mail Adresi. Lütfen Kontrol Edin." })); } #endregion var password = PasswordProcess.HesaplaSHA256(model.UserPassword).ToLower(); var user = await _userService.SingleOrDefaultAsync(x => x.Email == model.UserMail && x.Password == password && x.IsDeleted == false); if (user != null) { #region Session Settings var userType = await _userTypeService.GetByIdAsync((int)user.UserTypeId); SessionManagement.ActiveUserNameSurname = user.Name + " " + user.Surname; SessionManagement.ActiveUserPictureUrl = user.PictureUrl; SessionManagement.ActiveUserId = user.Id; if (userType.Code == UserTypes.Admin.GetHashCode()) { HttpContext.Session.SetString("IsAdmin", userType.Name); HttpContext.Session.GetString("IsAdmin"); SessionManagement.IsAdmin = true; SessionManagement.IsStudent = false; SessionManagement.IsJuryMember = false; SessionManagement.IsAssistant = false; SessionManagement.IsInstructor = false; SessionManagement.IsChair = false; SessionManagement.IsCoordinator = false; SessionManagement.IsExternalJuryMember = false; } if (userType.Code == UserTypes.Student.GetHashCode()) { HttpContext.Session.SetString("IsStudent", userType.Name); HttpContext.Session.GetString("IsStudent"); SessionManagement.IsAdmin = false; SessionManagement.IsStudent = true; SessionManagement.IsJuryMember = false; SessionManagement.IsAssistant = false; SessionManagement.IsInstructor = false; SessionManagement.IsChair = false; SessionManagement.IsCoordinator = false; SessionManagement.IsExternalJuryMember = false; } if (userType.Code == UserTypes.JuryMember.GetHashCode()) { HttpContext.Session.SetString("IsJuryMember", userType.Name); HttpContext.Session.GetString("IsJuryMember"); SessionManagement.IsAdmin = false; SessionManagement.IsStudent = false; SessionManagement.IsJuryMember = true; SessionManagement.IsAssistant = false; SessionManagement.IsInstructor = false; SessionManagement.IsChair = false; SessionManagement.IsCoordinator = false; SessionManagement.IsExternalJuryMember = false; } if (userType.Code == UserTypes.Assistant.GetHashCode()) { HttpContext.Session.SetString("IsAssistant", userType.Name); HttpContext.Session.GetString("IsAssistant"); SessionManagement.IsAdmin = false; SessionManagement.IsStudent = false; SessionManagement.IsJuryMember = false; SessionManagement.IsAssistant = true; SessionManagement.IsInstructor = false; SessionManagement.IsChair = false; SessionManagement.IsCoordinator = false; SessionManagement.IsExternalJuryMember = false; } if (userType.Code == UserTypes.Instructor.GetHashCode()) { HttpContext.Session.SetString("IsInstructor", userType.Name); HttpContext.Session.GetString("IsInstructor"); SessionManagement.IsAdmin = false; SessionManagement.IsStudent = false; SessionManagement.IsJuryMember = false; SessionManagement.IsAssistant = false; SessionManagement.IsInstructor = true; SessionManagement.IsChair = false; SessionManagement.IsCoordinator = false; SessionManagement.IsExternalJuryMember = false; } if (userType.Code == UserTypes.Chair.GetHashCode()) { HttpContext.Session.SetString("IsChair", userType.Name); HttpContext.Session.GetString("IsChair"); SessionManagement.IsAdmin = false; SessionManagement.IsStudent = false; SessionManagement.IsJuryMember = false; SessionManagement.IsAssistant = false; SessionManagement.IsInstructor = false; SessionManagement.IsChair = true; SessionManagement.IsCoordinator = false; SessionManagement.IsExternalJuryMember = false; } if (userType.Code == UserTypes.Coordinator.GetHashCode()) { HttpContext.Session.SetString("IsCoordinator", userType.Name); HttpContext.Session.GetString("IsCoordinator"); SessionManagement.IsAdmin = false; SessionManagement.IsStudent = false; SessionManagement.IsJuryMember = false; SessionManagement.IsAssistant = false; SessionManagement.IsInstructor = false; SessionManagement.IsChair = false; SessionManagement.IsCoordinator = true; SessionManagement.IsExternalJuryMember = false; } if (userType.Code == UserTypes.ExternalJuryMember.GetHashCode()) { HttpContext.Session.SetString("IsExternalJuryMember", userType.Name); HttpContext.Session.GetString("IsExternalJuryMember"); SessionManagement.IsAdmin = false; SessionManagement.IsStudent = false; SessionManagement.IsJuryMember = false; SessionManagement.IsAssistant = false; SessionManagement.IsInstructor = false; SessionManagement.IsChair = false; SessionManagement.IsCoordinator = false; SessionManagement.IsExternalJuryMember = true; } #endregion return(Json(new JsonMessage { HataMi = false, Baslik = "İşlem Başarılı", Mesaj = "Sisteme Giriş İşlemi Başarıyla Gerçekleşti." })); } return(Json(new JsonMessage { HataMi = true, Baslik = "İşlem Başarısız", Mesaj = "Geçersiz Kullanıcı Adı veya Şifre" })); }