コード例 #1
0
ファイル: HomeController.cs プロジェクト: Marknel/dbPOLL
        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();
        }
コード例 #2
0
ファイル: SysAdminController.cs プロジェクト: Marknel/dbPOLL
        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._%+-][email protected][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();
            }
        }
コード例 #3
0
ファイル: UserController.cs プロジェクト: Marknel/dbPOLL
        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._%+-][email protected][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");
        }
コード例 #4
0
ファイル: PollController.cs プロジェクト: Marknel/dbPOLL
        public ActionResult AssignPollCreator(int pollid, int[] selectedObjects, String pollname)
        {
            if (Session["uid"] == null || Session["uid"].ToString().Equals(""))
            {
                return RedirectToAction("Index", "Home");
            }
            if ((int)Session["user_type"] < User_Type.POLL_CREATOR)
            {
                return RedirectToAction("Invalid", "Home");
            }

            String errorString = "";

            new pollModel().assignPoll(pollid, selectedObjects);

            Assign_PollMasters pollMasters = new Assign_PollMasters();

            pollMasters.assigned = new userModel().displayAssignedUsers(pollid, User_Type.POLL_CREATOR);
            pollMasters.unassigned = new userModel().displayUnassignedUsers(pollid, User_Type.POLL_CREATOR);

                foreach (int id in selectedObjects)
                {
                    userModel u = new userModel();
                    u = u.getUser(id);
                    EmailController mail = new EmailController(pollname, u.username);

                    string mailSuccess = mail.send1();
                    if (!mailSuccess.Equals("Email sent successfully"))
                    {
                        errorString += u.username + "\n";
                        //throw new Exception(mailSuccess);
                    }
                }

            if(errorString.Length != 0)
                ViewData["emailError"] = "Could not send email to following Users: \n" + errorString;

            ViewData["pollid"] = pollid;
            ViewData["pollname"] = pollname;
            return View(pollMasters);
        }