コード例 #1
0
        public ActionResult SignUp(FormCollection collection)
        {
            string token = Guid.NewGuid().ToString();

            string email = collection["Email"];



            String password1 = collection["password1"].ToString();

            String password2 = collection["password2"].ToString();


            String firstName = collection["FirstName"].ToString();

            String lastName = collection["LastName"].ToString();

            Yoga_User newUser = new Yoga_User();

            newUser.U_Email            = email;
            newUser.U_First_Name       = firstName;
            newUser.U_Last_Name        = lastName;
            newUser.Roles_Id           = 4;
            newUser.Email_Confirmation = token;


            // check if user exist

            bool validUserExist = db.ValidateUserExist(email);

            if (validUserExist)
            {
                ViewBag.messageSignUp = "This user email is already register";

                ViewBag.StickyUser = newUser;

                //ViewBag.set

                return(View());
            }

            // Check if both password equals
            if (!string.Equals(password1, password2))
            {
                ViewBag.messageSignUp = "Please make sure the two passwords are the same";

                ViewBag.StickyUser = newUser;

                return(View());
            }



            // encode hash the password
            string test  = password2;
            string test2 = encoder.Encode(password2);

            newUser.U_Password = encoder.Encode(password2);
            //newUser.U_Password = password2;

            ViewBag.messageSignUp = "Account created successfully";


            // add user if not already existing
            try
            {
                //myDB.SaveChanges();
                db.CreateUser(newUser);
                Util.EmailSender.sendSignUpConfirmation(email, token);
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var entityValidationErrors in ex.EntityValidationErrors)
                {
                    foreach (var validationError in entityValidationErrors.ValidationErrors)
                    {
                        Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);

                        Console.WriteLine("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                    }
                }
            }



            return(View());
        }
コード例 #2
0
        public ActionResult CreateUser(FormCollection collection)
        {
            int    role  = Convert.ToInt32(collection["role"]);
            string email = collection["Email"];
            string fname = collection["FirstName"];
            string lname = collection["LastName"];
            string pass  = collection["Password"];

            //
            string   phone    = collection["Phone"];
            DateTime birthday = Convert.ToDateTime(collection["Birthday"]);



            Yoga_User y = new Yoga_User();

            //y.Roles_Id = db.getRoleId(role);
            y.Roles_Id = role;

            y.U_Email      = email;
            y.U_First_Name = fname;
            y.U_Last_Name  = lname;

            y.U_Phone    = phone;
            y.U_Birthday = birthday;


            // will do false so that the user need to update the temporary password
            y.Active = false;

            //  Generate temporary password and send confirmation email

            String tempPassword = Membership.GeneratePassword(8, 2);

            y.U_Password = encoder.Encode(pass);

            //string token = Guid.NewGuid().ToString();
            //Util.EmailSender.sendSignUpConfirmationTempPassword(email, token, tempPassword);



            // If teacher
            if (role == 2)
            {
                // "N/A" Me
                XDocument availabilities = new XDocument
                                           (
                    new XElement("Root",
                                 new XElement("Sunday",
                                              new XElement("Start", "N/A"),
                                              new XElement("End", "N/A")),
                                 new XElement("Monday",
                                              new XElement("Start", "N/A"),
                                              new XElement("End", "N/A")),
                                 new XElement("Tuesday",
                                              new XElement("Start", "N/A"),
                                              new XElement("End", "N/A")),
                                 new XElement("Wednesday",
                                              new XElement("Start", "N/A"),
                                              new XElement("End", "N/A")),
                                 new XElement("Thursday",
                                              new XElement("Start", "N/A"),
                                              new XElement("End", "N/A")),
                                 new XElement("Friday",
                                              new XElement("Start", "N/A"),
                                              new XElement("End", "N/A")),
                                 new XElement("Saturday",
                                              new XElement("Start", "N/A"),
                                              new XElement("End", "N/A"))
                                 ));

                y.Availability = availabilities.ToString();
            }
            if (db.ValidateUserExist(email))
            {
                return(View());
            }
            db.CreateUser(y);
            return(RedirectToAction("UserList"));
        }