createUser() 공개 메소드

public createUser ( int UserID, int UserType, string password, string name, string email, System.DateTime Expires_At, int SysAdmin_ID ) : bool
UserID int
UserType int
password string
name string
email string
Expires_At System.DateTime
SysAdmin_ID int
리턴 bool
예제 #1
0
        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");
        }
예제 #2
0
        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();
            }
        }