public JsonResult CompleteProfile(string firstName, string lastName, string location, string school, string major, bool checkbox)
        {
            try
            {

                if (!checkbox)
                {
                    return Json(new { Error = "Please accept the Vestn User Agreement before continuing." });
                }

                if (ValidationEngine.ValidateFirstName(firstName) != ValidationEngine.Success)
                {
                    return Json(new { Error = ValidationEngine.ValidateFirstName(firstName) });
                }

                if (ValidationEngine.ValidateLastName(lastName) != ValidationEngine.Success)
                {
                    return Json(new { Error = ValidationEngine.ValidateLastName(lastName) });
                }

                if (ValidationEngine.ValidateLocation(location) != ValidationEngine.Success)
                {
                    return Json(new { Error = ValidationEngine.ValidateLocation(location) });
                }

                if (ValidationEngine.ValidateSchool(school) != ValidationEngine.Success)
                {
                    return Json(new { Error = ValidationEngine.ValidateSchool(school) });
                }

                if (ValidationEngine.ValidateMajor(major) != ValidationEngine.Success)
                {
                    return Json(new { Error = ValidationEngine.ValidateMajor(major) });
                }

                User user = userManager.GetUser(User.Identity.Name);
                user.firstName = firstName;
                user.lastName = lastName;
                user.location = location;
                user.organization = school;
                user.major = major;
                user.isActive = 1;
                if (checkbox == true)
                {
                    UserAgreementAccessor uaa = new UserAgreementAccessor();
                    uaa.CreateAgreement(DateTime.Now, user.userName, "Agree", Request.ServerVariables["REMOTE_ADDR"]);
                }

                //update user with new values (this will not update tags or prof pic/resume)
                user = userManager.UpdateUser(user);

                user = userManager.UpdateUser(user);

                if (user.profilePicture != null)
                {
                    while (user.profilePictureThumbnail == null)
                    {
                        user = userManager.GetUser(user.id);
                        Thread.Sleep(200);
                    }
                }

                return Json(new { UserInformation = new { FirstName = firstName, LastName = lastName, Location = location, School = school, Major = major } });
            }
            catch (Exception ex)
            {
                logAccessor.CreateLog(DateTime.Now, this.GetType().ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), ex.ToString());
                return Json(new { Status = 0 });
            }
        }
示例#2
0
        public string Register(string email, string password, string networkJoinCode = null, string firstName = null, string lastName = null, string type = "standard")
        {
            if (Request != null)
            {
                if (Request.RequestType.Equals("OPTIONS", StringComparison.InvariantCultureIgnoreCase))
                {
                    return null;
                }
            }
            try
            {
                CommunicationManager communicationManager = new CommunicationManager();
                string userName = email.Substring(0, email.IndexOf('@'));
                userName = userName.Replace("+", "");
                userName = userName.Replace(".", "");
                RegisterModel model = new RegisterModel { Email = email, UserName = userName, Password = password, ConfirmPassword = password };
                if (ValidationEngine.ValidateEmail(model.Email) != ValidationEngine.Success)
                {
                    return AddErrorHeader("Invalid Email", 1);
                }
                if (!userManager.CheckDuplicateEmail(model.Email))
                {
                    return AddErrorHeader("A user with that email already exists in our database", 1);
                }
                if (ValidationEngine.ValidateUsername(model.UserName) != ValidationEngine.Success)
                {
                    return AddErrorHeader(ValidationEngine.ValidateUsername(model.UserName), 1);
                }
                if (!userManager.CheckDuplicateUsername(model.UserName))
                {
                    return AddErrorHeader("A user with that username already exists in our database", 1);
                }
                if (ValidationEngine.ValidatePassword(model.Password) != ValidationEngine.Success)
                {
                    return AddErrorHeader(ValidationEngine.ValidateUsername(model.Password), 1);
                }
                if (model.Password != model.ConfirmPassword)
                {
                    return AddErrorHeader("Password fields do not match", 1);
                }
                if (ModelState.IsValid)
                {
                    User newUser = model.toUser();
                    newUser.profileURL = newUser.userName;
                    newUser.firstName = firstName;
                    newUser.lastName = lastName;
                    if (networkJoinCode != null)
                    {
                        NetworkManager nm = new NetworkManager();
                        Network network = nm.GetNetworkByIdentifier(networkJoinCode);
                        if (network != null)
                        {
                            newUser.title = "student";
                            newUser.organization = network.name;
                        }
                    }
                    newUser = userManager.CreateUser(newUser, model.Password);

                    UserAgreementAccessor uaa = new UserAgreementAccessor();
                    if (Request.ServerVariables["REMOTE_ADDR"] != null)
                    {
                        uaa.CreateAgreement(DateTime.Now, newUser.userName, "Agree", Request.ServerVariables["REMOTE_ADDR"]);
                    }
                    else
                    {
                        uaa.CreateAgreement(DateTime.Now, newUser.userName, "Agree", "IP not detectable");
                    }

                    userManager.ActivateUser(newUser, true);
                    //communicationManager.SendVerificationMail(userManager.GetProviderUserKey(newUser), newUser.userName, newUser.email);

                    if (networkJoinCode != null)
                    {
                        NetworkManager nm = new NetworkManager();
                        Network network = nm.GetNetworkByIdentifier(networkJoinCode);
                        if (network != null)
                        {
                            if (type == "network")
                            {
                                nm.AddNetworkAdmin(network.id, email);
                            }
                            else
                            {
                                string[] emailArray = { email };
                                nm.AddNetworkUsers(network, emailArray);
                            }
                        }
                    }
                    userManager.SendVerifyEmail(email);
                    AnalyticsAccessor aa = new AnalyticsAccessor();
                    aa.CreateAnalytic("Register", DateTime.Now, newUser.userName);
                    AuthenticaitonEngine authEngine = new AuthenticaitonEngine();
                    string token = authEngine.logIn(newUser.id, newUser.userName);
                    JsonModels.RegisterResponse rr = new JsonModels.RegisterResponse();
                    rr.userId = newUser.id;
                    rr.token = token;
                    return AddSuccessHeader(Serialize(rr));
                }
                else
                {
                    return AddErrorHeader("User Model Not Valid", 1);
                }
            }
            catch (Exception ex)
            {
                logAccessor.CreateLog(DateTime.Now, this.GetType().ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), ex.ToString());
                return AddErrorHeader("Something went wrong while creating this user", 1);
            }
        }