public async Task<ActionResult> Register(RegisterViewModel model) { var exist = LoginPersistance.GetByUserName(model.IdNumber); if (null != exist) ModelState.AddModelError("", "Pengguna dengan Kad Pengenalan : " + model.IdNumber + " sudah wujud."); // check validity of id number if (!AtmHelper.MyKadValidation(model.IdNumber)) ModelState.AddModelError("", "Kad Pengenalan : " + model.IdNumber + " tidak sah."); string message; if (!AtmHelper.MyKadAgeValidation(model.IdNumber, out message)) ModelState.AddModelError("", message); // checking existing member of atm var atmexist = ObjectBuilder.GetObject<IApplicantPersistence>("ApplicantPersistence").ExistingAtmMember(model.IdNumber); if (null != atmexist) { if (atmexist.ExistingMemberStatus.Code.Trim() == "1") ModelState.AddModelError("", "Anda tidak layak memohon kerana anda sedang berkhidmat di dalam ATM"); if (atmexist.ExistingMemberStatus.Code.Trim() == "4") ModelState.AddModelError("", "Anda tidak layak memohon kerana pernah menyertai ATM dan telah diberhentikan atas sebab tatatertib"); } if (ModelState.IsValid) { // check no kad pengenalan valid or not var rand = new Random(); model.IdNumber = model.IdNumber.Replace("-", ""); model.IdNumber = model.IdNumber.Trim(); var login = new LoginUser() { FullName = model.FullName, UserName = model.IdNumber, LoginId = model.IdNumber, Email = model.Email, AlternativeEmail = model.AlternateEmail, Salt = Guid.NewGuid().ToString(), Password = "******" + rand.Next(1, 9999).ToString().PadLeft(4, '0'), FirstTime = true, IsLocked = false, CreatedDt = DateTime.Now, CreatedBy = "Registration" }; var id = login.Save(); // send notification email var from = ConfigurationManager.AppSettings["fromEmail"]; var url = this.Request.Url; if (url != null) { var loginurl = ConfigurationManager.AppSettings["server"] + "/Account/Login"; var templatepath = Path.Combine(System.Web.HttpContext.Current.Server.MapPath(@"~/Templates"), "Registration.html"); var mail = new MailService(); mail.Send(from, new List<string> { login.Email, login.AlternativeEmail }, null, null, login, loginurl, templatepath, null); } TempData["Message"] = "Id pengguna dan Kata laluan telah dihantar ke emel yang didaftarkan. Sila semak emel anda."; return RedirectToAction("Login", "Account"); } return View(model); }
public ActionResult SubmitUser(LoginUser loguser) { if (loguser.LoginRole != null && !string.IsNullOrWhiteSpace(loguser.LoginRole.Roles)) { if (loguser.LoginRole != null) { if (loguser.LoginRole.Roles != RolesString.AWAM) { loguser.Email = "NA"; loguser.AlternativeEmail = "NA"; if (loguser.UserId == 0) loguser.Salt = Guid.NewGuid().ToString(); } } loguser.CreatedDt = DateTime.Now; loguser.CreatedBy = User.Identity.Name; loguser.IsLocked = loguser.Status != "Aktif"; if (loguser.Save() > 0) { var user = ObjectBuilder.GetObject<ILoginUserPersistance>("LoginUserPersistance").GetByUserName(User.Identity.Name); if (null != user) ObjectBuilder.GetObject<ILoginUserPersistance>("LoginUserPersistance").LoggingUser(user.UserId, LogStatusCodeString.Create_User, User.Identity.Name, DateTime.Now); return Json(new { OK = true, message = "Berjaya." }); } } return Json(new { OK = false, message = "Tidak Berjaya." }); }
public ActionResult SubmitAndEmailUser(LoginUser loguser) { if (loguser.LoginRole != null && !string.IsNullOrWhiteSpace(loguser.Email)) { if (loguser.LoginRole != null) { if (loguser.LoginRole.Roles != RolesString.AWAM) { loguser.Email = "NA"; loguser.AlternativeEmail = "NA"; if (loguser.UserId == 0) loguser.Salt = Guid.NewGuid().ToString(); } } if (loguser.UserId == 0) { loguser.CreatedDt = DateTime.Now; loguser.CreatedBy = User.Identity.Name; } loguser.IsLocked = loguser.Status != "Aktif"; loguser.FirstTime = true; if (loguser.Save() > 0) { // change the password if the is new password if (loguser.UserId != 0) loguser.ChangePassword(loguser.Password); var user = ObjectBuilder.GetObject<ILoginUserPersistance>("LoginUserPersistance").GetByUserName(User.Identity.Name); if (null != user) { var url = this.Request.Url; if (url != null) { var from = ConfigurationManager.AppSettings["fromEmail"]; var loginurl = ConfigurationManager.AppSettings["server"] + "/Account/Login"; var templatepath = Path.Combine(System.Web.HttpContext.Current.Server.MapPath(@"~/Templates"), "TempPassword.html"); var mail = new MailService(); mail.SendMail("[JOM MASUK TENTERA]Notifikasi Kata Laluan Sementara", from, new List<string> { loguser.Email, loguser.AlternativeEmail }, null, null, loguser, loginurl, templatepath, DateTime.Now); } ObjectBuilder.GetObject<ILoginUserPersistance>("LoginUserPersistance").LoggingUser(user.UserId, LogStatusCodeString.Create_User, User.Identity.Name, DateTime.Now); } return Json(new { OK = true, message = "Berjaya." }); } } return Json(new { OK = false, message = "Tidak Berjaya." }); }