public ActionResult RegisterUser(string email, string name, int user_type) { // Basic check to see if the user is Authenticated. if (Session["uid"] == null || Session["uid"].ToString().Equals("")) { return RedirectToAction("Index", "Home"); } if ((int)Session["user_type"] < User_Type.POLL_MASTER) { return RedirectToAction("Invalid", "Home"); } bool errorspresent = false; // VALIDATE FORM DATA! if (name == null || name == "") { ViewData["nameError"] = "Above field must contain a name!"; errorspresent = true; } else if (name.Length > 64) { ViewData["nameError"] = "Name is too long, maximum length allowed is 64 characters"; errorspresent = true; } //if (email == null || System.Text.RegularExpressions.Regex.IsMatch(email, @"^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<= // [0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$")) if (email == null || !Regex.IsMatch(email, @"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$", RegexOptions.IgnoreCase)) { ViewData["emailError"] = "Above field must contain a valid email address!"; errorspresent = true; } else if (email.Length > 64) { ViewData["emailError"] = "Email address is too long, maximum length allowed is 64 characters"; errorspresent = true; } if (errorspresent) { buildSelectList(); return View(); } userModel user = new userModel(); // Get the ID for a new user int UserID = user.getNewID(); string password = user.Password_Generator(); DateTime expiry_Date = DateTime.Now.AddYears(10); // Create the user if (!user.createUser(UserID, user_type, password, name, email, (int)Session["uid"])) { ViewData["Message"] = "A user account with this email address already exists"; buildSelectList(); return View(); } // Send Email to new user EmailController mail = new EmailController(email, password, email); string mailSuccess = mail.send(); if (!mailSuccess.Equals("Email sent successfully")) { throw new Exception(mailSuccess); } return RedirectToAction("RegisterUserSuccess", "User"); }
public ActionResult ResetPassword(string email) { int uid; userModel user = new userModel(); // if (email == null || System.Text.RegularExpressions.Regex.IsMatch(email, @"^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<= // [0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$")) // { // ViewData["emailError"] = "Above field must contain a valid email address!"; // error = true; // } uid = user.verify(email); if (uid == 0) { ViewData["outcome"] = "No account with this email address was found"; return View(); } //generate new password string newPassword = user.Password_Generator(); //store new password in db user.changePassword(uid, newPassword); //send new password in email EmailController mail = new EmailController(email, newPassword, email); string mailSuccess = mail.send(); if (!mailSuccess.Equals("Email sent successfully")) { ViewData["outcome"] = "An error occurred whilst trying to reset your password, please try again in a few moments or contact your System Administrator."; } else ViewData["outcome"] = "Password successfully reset! Please check your email for your new password"; ViewData["emailError"] = mailSuccess; return View(); }
public ActionResult RegisterUser(String name, String email, string expiry) { // Basic check to see if the user is Authenticated. if (Session["uid"] == null || Session["uid"].ToString().Equals("")) { return RedirectToAction("Index", "Home"); } if (!Session["sysadmin"].ToString().Equals("true")) { return RedirectToAction("Invalid", "Home"); } bool errorspresent = false; int SysAdmin_ID = (int)Session["uid"]; // Allows insertion of Australian formatted dates CultureInfo ci = Thread.CurrentThread.CurrentCulture; ci = new CultureInfo("en-AU"); int expInt = 0; //returns the max question ID in the questions table int UserID = new userModel().getNewID(); // VALIDATE FORM DATA! if (name == null || name == "") { ViewData["nameError"] = "Above field must contain a name!"; errorspresent = true; } if (email == null || !Regex.IsMatch(email, @"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$", RegexOptions.IgnoreCase)) { ViewData["emailError"] = "Above field must contain a valid email address!"; errorspresent = true; } if (expiry == null || expiry == "") expInt = 12; else if (!System.Text.RegularExpressions.Regex.IsMatch(expiry, @"^\d+$")) { ViewData["expiryError"] = "Expiry date must be a whole non-negative number"; errorspresent = true; } else { try { //converts user num into string expInt = int.Parse(expiry); } catch (Exception e) { //Not an int. do not insert and throw view error to user. ViewData["expiryError"] = "!ERROR: " + e.Message; errorspresent = true; } } if (errorspresent) { return View(); } try { userModel user = new userModel(); DateTime expiry_Date = DateTime.Now.AddMonths(expInt); string password = user.Password_Generator(); //Build question (Autoid, short answer type = 1, question text from form, date, pollid from poll it is created it user.createUser(UserID, 4, password, name, email, expiry_Date, SysAdmin_ID); EmailController mail = new EmailController(email, password, email); string mailSuccess = mail.send(); if (!mailSuccess.Equals("Email sent successfully")) { throw new Exception(mailSuccess); } return RedirectToAction("RegisterUserSuccess", "SysAdmin"); } catch (Exception e) { ViewData["error1"] = "!ERROR: " + e.Message; return View(); } }