Ejemplo n.º 1
0
        public ActionResult Register(registerViewModel model, HttpPostedFileBase file)
        {
            bool hasError = false;
            ViewBag.username = model.UserName;
            ViewBag.identifier = mem.imRegistering(true);
            int countLanguageValid = (from lang in user.languages
                                      where lang.languageID == model.languageDefined
                                      select lang).Count();
            int countProfile = (from us in user.UserProfiles
                                where us.UserName == model.UserName
                                select us).Count();
            if (countProfile > 0)
            {
                if ((from def in user.userDefinition
                     join use in user.UserProfiles
                         on def.usernameFK equals use
                     where use.UserName == model.UserName
                     select def.isArchived).First())
                {
                    ModelState.AddModelError("", "This username is archived currently, please try an alternative");
                    hasError = true;
                }
            }
            if (countLanguageValid < 1)
            {
                hasError = true;
                ModelState.AddModelError("", "Please check your language is valid");
            }
            if (model.Password != null)
            {
                if (model.Password.Length < 8 || sec.checkLower(model.Password) == false || sec.checkUpper(model.Password) == false || sec.containsNumber(model.Password) == false)
                {
                    hasError = true;
                    ModelState.AddModelError("", "Your passwords does not pass the validation rules");
                }
                if (model.Password != model.ConfirmPassword) { ModelState.AddModelError("", "Your passwords must match"); hasError = true; }
            }
            if (model.UserName != null && model.UserName.Length < 4) { ModelState.AddModelError("", "Your username must be at least 4 characters long"); hasError = true; }
            {
                if (model.securityQuestionID == -1) { ModelState.AddModelError("", "A security question must be selected"); hasError = true; }
                bool validPersonType = mem.personTypeValid(model.personType);
                if (validPersonType == false) { ModelState.AddModelError("", "Your person type is not recognised"); hasError = true; }

                if (hasError) { return View(new registerViewModel()); }
                UsersContext yt = new UsersContext();
                if (ModelState.IsValid && hasError == false)
                {
                    // Attempt to register the user
                    try
                    {

                        memadd.registerUser(model, false);
                        loginViewModel loggingIn = new loginViewModel();
                        loggingIn.UserName = model.UserName;
                        loggingIn.Password = model.Password;
                        loggingIn.RememberMe = true;
                        Login(loggingIn, "/Member/memberDetails/");
                        user.SaveChanges();
                        //            memadd.addUsage(model.UserName);
                        files.updateImage(file, model.UserName, "member");
                        {
                            ViewBag.Title = "Welcome " + WebSecurity.CurrentUserName + " check your details here";
                            return RedirectToAction("memberDetails", "member");
                        }
                    }
                    catch (MembershipCreateUserException e)
                    {
                        ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                    }
                }

                // If we got this far, something failed, redisplay form
                return View(model);
            }
        }
Ejemplo n.º 2
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (UsersContext db = new UsersContext())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        if (model.Password.Length < 8 || sec.checkLower(model.Password) == false || sec.checkUpper(model.Password) == false || sec.containsNumber(model.Password) == false)
                        {
                            ModelState.AddModelError("", "Your passwords does not pass the validation rules");
                            return View();
                        }

                        //db.UserProfiles.Add(new UserProfile { UserName = model.UserName });
                        //db.SaveChanges();

                        //OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        //OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);
                        registerViewModel external = new registerViewModel()
                        {
                            UserName = model.UserName,
                            Password = model.Password,
                            interestPublic = false,
                            activitiesPublic = false,
                            followingPublic = false,
                            DOBPublic = false,
                            styleSheetName = "Foundation",
                            personType = (from pt in db.personType
                                          where pt.personTypeID == 1
                                          select pt.Description).FirstOrDefault(),
                            onlineImg = model.onlineImg,
                            useOnlineImg = model.useOnline
                        };
                        memadd.registerUser(external, true);
                        memadd.addUsage(model.UserName);
                        {
                            ViewBag.Title = "Welcome " + model.UserName + " check your details here";
                            mem.imRegistering(false);
                            return RedirectToAction("memberDetails", "member");
                        }
                        //return RedirectToLocal(returnUrl);
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
Ejemplo n.º 3
0
 // GET: /Account/Register
 public ActionResult Register(registerViewModel model)
 {
     ViewBag.identifier = mem.imRegistering(true);
     return View(new registerViewModel());
 }
Ejemplo n.º 4
0
        public void registerUser(registerViewModel model, Boolean isExternal)
        {
            var secureSetting = "";
            if (model.isSecure) { secureSetting = model.secureString; }
            WebSecurity.CreateUserAndAccount(model.UserName, model.Password, model.status);
            WebSecurity.Login(model.UserName, model.Password);
            using (var db = new UsersContext())
            {
                userDefinition userSubmission = new userDefinition
                {
                    showOuter = true,
                    homePage = "/Member/memberDetails/",
                    activitiesPublic = model.activitiesPublic,
                    DOBPublic = model.DOBPublic,
                    followingPublic = model.followingPublic,
                    interestPublic = model.interestPublic,
                    usernameFK = (from userDefined in db.UserProfiles
                                  where userDefined.UserName == model.UserName
                                  select userDefined).FirstOrDefault(),
                };
                if(isExternal)
                {
                    userSubmission.useOnlineImg = model.useOnlineImg;
                    userSubmission.onlineUrl = model.onlineImg;
                    userSubmission.language = (from lang in db.languages
                                               where lang.Description == "English"
                                               select lang).First();
                }
                if (isExternal == false)
                {
                    var secQuestion = (from secq in db.securityQuestions
                                       where secq.questionID == model.securityQuestionID
                                       select secq).First();
                    userSubmission.language = (from lang in db.languages
                                               where lang.languageID == model.languageDefined
                                               select lang).First();
                    userSubmission.securityQuestionID = secQuestion;
                    userSubmission.secure = sec.GetMD5Hash(secureSetting);
                    userSubmission.emailAddress = model.emailAddress;
                    userSubmission.status = model.status;
                    userSubmission.recommendedBy = model.recommendedBy;
                    userSubmission.securityAnswer = model.securityAnswer;
                    userSubmission.personTypeID = (from ptype in db.personType
                                                   where ptype.Description == model.personType
                                                   select ptype).First();
                    userSubmission.useOnlineImg = false;
                }

                db.userDefinition.Add(userSubmission);

                db.SaveChanges();
                mem.imRegistering(false);
                var user = db.userDefinition.Where(u => u.emailAddress == model.emailAddress)
                    .OrderBy(u => u.ID).FirstOrDefault();

                db.highlightsComputedMessages.Add(
                    new highlightsComputedMessage
                    {
                        createdUserID = (from users in db.UserProfiles
                                         orderby users.UserId descending
                                         select users.UserId).First(),
                        sourceDefinition = model.UserName,
                        highlightID = (from highlights in db.highlightsPerType
                                       where highlights.highlightMethod == "personRegister"
                                       select highlights).First()
                    }
                );
                db.SaveChanges();

                memberServices memThis = new memberServices();
                var userIdDefined = (from idd in db.UserProfiles
                                     orderby idd.UserId descending
                                     select idd.UserId).First();
                getActivityForIntRank(model.personType, userIdDefined, model.UserName, model.styleSheetName);
            }
        }