예제 #1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {

                dx_user use = new dx_user();
                use.fname = model.FirstName;
                use.lname = model.LastName;
                use.phone = model.Phone;
                use.questionid = Int32.Parse(model.Squestion);
                use.role = model.Position;
                use.userid = model.Email;
                use.anshash = generateHash(model.Answer);
                use.accesslevel = 1; //
                use.pwdhash = generateHash(model.Password, generateSalt());
                use.actcodehash = "111";
                use.dob = new DateTime();
                database.dx_user.Add(use);
                int success = database.SaveChanges();
                if (success > 0)
                {
                    FormsAuthentication.SetAuthCookie(model.Email, false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    //ModelState.AddModelError("", ErrorCodeToString("1"));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
예제 #2
0
        private bool validateModelRegister(RegisterModel model)
        {
            bool isValid = true;
            try
            {

                string captchaid = Request.Form["CaptchaGuid"];
                string captchaValue = Request.Form["Captcha"];

                if (model.FirstName == null || model.LastName == null
                    || model.Phone == null || model.Password == null || model.Position == null
                    || model.Email == null || model.ConfirmPassword == null
                    || model.Captcha == null || model.Answer == null)
                {

                    ModelState.AddModelError("", "Invalid Values!");
                    return false;
                }

                if (isRegisterRegexValid(model) == false)
                {
                    return false;
                }

                if (!("ceo".Equals(model.Position) || "vp".Equals(model.Position) || "employee".Equals(model.Position) || "manager".Equals(model.Position)))
                {
                    ModelState.AddModelError("", "Invalid Role");
                    return false;
                }

                foreach (int i in model.Department)
                {
                    if (i < 1 || i > 7)
                    {
                        ModelState.AddModelError("", "Incorrect department");
                        return false;
                    }

                }

                if (model.Squestion > 9 || model.Squestion < 1)
                {
                    ModelState.AddModelError("", "Incorrect secrate question");
                    return false;
                }

                //Validate captcha

                WebClient captchaCliden = new WebClient();
                string reponseCaptchaService = captchaCliden.DownloadString(
                  "http://www.opencaptcha.com/validate.php?img="
                    + captchaid + "&ans=" + captchaValue);

                if (!"pass".Equals(reponseCaptchaService))
                {
                    ModelState.AddModelError("", "Captcha didn't match, please try again!");
                    return false;
                }

                if ((Constants.POSITION_MANAGER_USER.Equals(model.Position) || Constants.POSITION_EMPLOYEE_USER.Equals(model.Position)) && model.Department.ToList().Count > 1)
                {
                    ModelState.AddModelError("", "Your position can not have multiple departments!");
                    return false;
                }

            }
            catch (Exception)
            {
                isValid = false;
                ModelState.AddModelError("", "Invalid request Please try after some time!");

            }
            return isValid;
        }
예제 #3
0
        public ActionResult Register(RegisterModel model)
        {
            try
            {
                populateDepartmenetsList();

                if (ModelState.IsValid)
                {

                    FormsAuthentication.SignOut();
                    if (validateModelRegister(model) == false)
                    {
                        ViewBag.CaptchaGuid = Guid.NewGuid().ToString("N");
                        return View(model);
                    }

                    ViewBag.CaptchaGuid = Guid.NewGuid().ToString("N");

                    var allusers = from usertabel in database.DX_USER where usertabel.userid == model.Email select usertabel;
                    if (allusers.ToList().Count == 1)
                    {
                        ModelState.AddModelError("", "Email id not unique, please enter a diffrent valid email id!");
                        return View(model);

                    }
                    var alldepartment = from usertabel in database.DX_DEPARTMENT where model.Department.Contains(usertabel.deptid) select usertabel;

                    if (Constants.POSITION_CEO_USER.Equals(model.Position))
                    {

                        alldepartment = from usertabel in database.DX_DEPARTMENT select usertabel;

                    }

                    if (alldepartment.ToList().Count >= 1)
                    {

                        DX_USER user = new DX_USER();
                        user.fname = model.FirstName;
                        user.lname = model.LastName;
                        user.phone = model.Phone;
                        user.questionid = model.Squestion;
                        user.role = model.Position;
                        user.userid = model.Email;
                        user.anshash = generateHash(model.Answer.ToLower());
                        user.accesslevel = Constants.TEMP_USER_ACCESS;
                        user.salt = generateSalt();
                        user.pwdhash = generateHash(user.salt, model.Password);
                        user.actcodehash = "dummycode";
                        database.DX_USER.AddObject(user);//Add user

                        foreach (DX_DEPARTMENT dept in alldepartment.ToList())
                        {
                            DX_USERDEPT userDept = new DX_USERDEPT();
                            userDept.deptid = dept.deptid;
                            userDept.userid = model.Email;
                            database.DX_USERDEPT.AddObject(userDept);//Add department
                        }

                        int success = database.SaveChanges();
                        if (success > 0)
                        {
                            String message = Environment.NewLine + "Hi " + model.FirstName + "," + Environment.NewLine
                                + "Thank you for registering with Docbox!" + Environment.NewLine
                                + "You will soon get notification, once you are been approved by Docbox Administrator" + Environment.NewLine
                                    + "- Docbox Team";
                            try
                            {
                                EmailMessaging.sendMessage(model.Email, message, "Notification");
                            }
                            catch
                            {
                                ModelState.AddModelError("", "User created but unabe to log in at this point of time try logging in after some time!");

                                return View(model);
                            }

                            FormsAuthentication.SetAuthCookie(model.Email, false);
                            return RedirectToAction("Index", "TempUser");
                        }
                        else
                        {
                            ModelState.AddModelError("", "User can not be registered, Please try after some time!");
                            return View(model);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Invalid Department Select Correct Department");
                        return View(model);
                    }

                }
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "Invalid request please try after some time! ");
            }
            // If we got this far, something failed, redisplay form
            return View(model);
        }
예제 #4
0
        private bool isRegisterRegexValid(RegisterModel model)
        {
            if (!Regex.IsMatch(model.FirstName, @"^[a-zA-Z]{1,20}$"))
            {
                ModelState.AddModelError("", "First name incorrect please try agian!!.");
                return false;
            }
            if (!Regex.IsMatch(model.LastName, @"^[a-zA-Z]{1,20}$"))
            {
                ModelState.AddModelError("", "Last name incorrect please try agian!!.");
                return false;
            }

            if (!Regex.IsMatch(model.Email, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"))
            {
                ModelState.AddModelError("", "Email-id incorrect please try agian!!.");
                return false;
            }

            if (!Regex.IsMatch(model.Phone, @"^(\d{10})$"))
            {
                ModelState.AddModelError("", "Phone incorrect please try agian!!.");
                return false;
            }
            if (!Regex.IsMatch(model.Password, @"^.*(?=.{10,18})(?=.*\d)(?=.*[A-Za-z])(?=.*[@%&#]{0,}).*$"))
            {
                ModelState.AddModelError("", "Password incorrect please try agian!!.");
                return false;
            }
            if (!Regex.IsMatch(model.ConfirmPassword, @"^.*(?=.{10,18})(?=.*\d)(?=.*[A-Za-z])(?=.*[@%&#]{0,}).*$"))
            {
                ModelState.AddModelError("", "Confirm Password incorrect please try agian!!.");
                return false;
            }
            if (!Regex.IsMatch(model.Position, @"^[a-zA-Z]{1,20}$"))
            {
                ModelState.AddModelError("", "Position incorrect please try agian!!.");
                return false;
            }
            if (!Regex.IsMatch(model.Answer, @"^[a-zA-Z]{1,20}$"))
            {
                ModelState.AddModelError("", "Answer incorrect please try agian!!.");
                return false;
            }

            return true;
        }
예제 #5
0
 public ActionResult Register()
 {
     ViewBag.CaptchaGuid = Guid.NewGuid().ToString("N");
     RegisterModel model = new RegisterModel();
     model.Department = new List<int>();
     populateDepartmenetsList();
     return View(model);
 }