//When activation link is clicked public async Task<ActionResult> CompletingRegistration(string _uname, string _str) { TBL_WEBUSERS tbl = new TBL_WEBUSERS(); tbl = (from a in db.TBL_WEBUSERS where a.USERNAME == _uname && a.SHA_PASSWORD == _str select a).Single(); tbl.ACTIVE = true; DateTime now = DateTime.Now; tbl.DATE_VERIFIED = now; db.Entry(tbl).State = EntityState.Modified; await db.SaveChangesAsync(); sendEmail("Account Activation", "Account Activated", "Username: "******" has been activated. <br/> You can now use the Username and Temporary Password provided to you. <br/> Thank you!", tbl.EMAIL); return View(); }
public async Task<ActionResult> Create(RegViewModel tblUser) //[Bind(Include = "lastname,firstname,middlename,address,username,contactno,email,region,city") //string lname, string fname, string mname, string nostreet, string city, string region, string uname, string password, string cpassword, string email { RegViewModel vmodel = new RegViewModel(); TBL_WEBUSERS tbl = new TBL_WEBUSERS(); if (ModelState.IsValid) { TBL_WEBUSERS ifExist = await db.TBL_WEBUSERS.FirstOrDefaultAsync(m => m.USERNAME == tblUser.username); if (!(ifExist == null)) { vmodel._list = GlobalVar.BranchList; vmodel._listRegion = GlobalVar.RegionList; vmodel.isError = 2; vmodel.errMessage = "Username already taken. Kindly choose different username."; return View(vmodel); } ifExist = await db.TBL_WEBUSERS.FirstOrDefaultAsync(m => m.EMAIL == tblUser.email); if (!(ifExist == null)) { vmodel._list = GlobalVar.BranchList; vmodel._listRegion = GlobalVar.RegionList; vmodel.isError = 2; vmodel.errMessage = "Email already registered. Please choose different email address or use password recovery system."; return View(vmodel); } tbl.LASTNAME = tblUser.lastname; tbl.FIRSTNAME = tblUser.firstname; tbl.MIDDLENAME = tblUser.middlename; tbl.MAILING_ADDRESS = tblUser.address; tbl.CITY = tblUser.city; tbl.COMP = "MLY"; tbl.REGION = tblUser.region; tbl.USERNAME = tblUser.username; tbl.CONTACT_NUMBER = tblUser.contactno; //tbl.PASSWORD = password; tbl.USER_CODE = Yfunction.generateSerial(9, "ITDept6953069"); tbl.SHA_PASSWORD = Yfunction.generateRandomString(12, "ITDept6953069"); if (!string.IsNullOrEmpty(tblUser.email)) { tbl.EMAIL = tblUser.email; //shaPass = Yfunction.generateRandomString(12, myElement); } DateTime now = DateTime.Now; tbl.DATE_REGISTERED = now; //tbl.BRANCH_CODE = tblUser.bCode; tbl.USER_TYPE = "CLIENT"; tbl.BRANCH_CODE = "HardCoded Branch Code"; db.TBL_WEBUSERS.Add(tbl); await db.SaveChangesAsync(); string tempname = tbl.FIRSTNAME + " " + tbl.LASTNAME; string _bod = string.Format("Dear Sir/Madam {0}, <BR/><BR/> Your account is now registered to RCTPL Web App. Thank you. <BR/> Please click on the link to activate your registration: <a href=\"https://" + WebConfigurationManager.AppSettings["ServerIP"] + "/WEBUSERS/CompletingRegistration/{1}/{2}\">Activate Registration</a> <br/><br/>Username: {3} <br/>Password: {4} <br/><br/> Kindly replace your temporary password as soon as you login. <br/>Thank you!", tempname, tbl.USERNAME, tbl.SHA_PASSWORD, tbl.USERNAME, tbl.SHA_PASSWORD); sendEmail("RCTPL Web Registration", "Registration Confirmation", _bod, tblUser.email); vmodel._list = GlobalVar.BranchList; vmodel._listRegion = GlobalVar.RegionList; vmodel.isError = 1; return View(vmodel); } vmodel._list = GlobalVar.BranchList; vmodel._listRegion = GlobalVar.RegionList; vmodel.isError = 2; vmodel.errMessage = "Something went wrong. Please click Register again for details."; return View(vmodel); }