public virtual ActionResult UpdateProfile(UpdateProfileModel model, Contact contact) { var userModel = new User() { UserName = this.UserName(), FirstName = model.FirstName, LastName = model.LastName, Signature = model.Signature, AppendSignatureToTitle = model.AppendSignatureToTitle, HasAllowedCommunication = model.HasAllowedCommunication }; //var contact = model.Contact; //var session = SessionService.Session(); var currentUser = Account.User();//session.User(User.Identity.Name); model.ShowSignatureField = currentUser.IsAtLeastInCatalogRole(Roles.Plugger); model.ShowContactInfo = currentUser.PricingPlan.CustomContactUs && currentUser.IsAtLeastInCatalogRole(Roles.Admin); //update the user's profile in the database try { var contactList = AccountService.UpdateProfile(userModel, new List<Contact>() { contact }); UserEventLogService.LogUserEvent(UserActions.UpdateProfile); // UpdateModelWith the user dataSession cached in dataSession SessionService.Session().InitializeSession(true); CacheService.CacheUpdate(CacheService.CacheKeys.SiteProfile); var friendly = userModel.FullName(); SetFriendlyNameCookie(friendly); this.FeedbackInfo("Successfully updated your profile"); model.Contact = contactList.FirstOrDefault(); ViewData["PasswordLength"] = AccountService.MinPasswordLength; } catch (Exception ex){ Log.Error(ex); //model.ShowSignatureField = user.IsAtLeastInCatalogRole(Roles.Plugger); ModelState.AddModelError("", SystemErrors.PasswordChangeFailed); this.FeedbackError("There was an error updating your profile"); } model.NavigationLocation = new string[] { "Account", "Profile" }; model.PageTitle = "Update Profile"; model.PageMessage = "My Profile"; return View(model); }
public virtual ActionResult Register(RegisterModel model) { //set username to email address //contentModel.UserName = contentModel.Email; if (ModelState.IsValid) { if (AccountService.UserExists(model.Email)) { ModelState.AddModelError("Email", SystemErrors.UserAlreadyRegistered); } else if (!model.HasAgreedToPrivacyPolicy){ ModelState.AddModelError("HasAgreedToPrivacyPolicy", "We''re sorry, we can only register you if you accept our Terms of Use."); } else { // Check invitation code Invitation inv = null; try { inv = UserManagementService.GetInvitation(model.InviteId, model.Email); } catch (Exception ex){ Log.Error(ex); ModelState.AddModelError("InviteId", SystemErrors.InviteCodeNoMatch); } if (inv != null) { // model.SiteProfile = SiteProfileData.SiteProfile(inv.InvitedByUser.SiteProfileId, true); switch (inv.InvitationStatus) { case (int)InvitationStatusCodes.Open: { model.Invitation = inv; // Attempt to register the myUser //MembershipCreateStatus createStatus = _ms.CreateUser(contentModel.Email, contentModel.Password, contentModel.Email); if (String.IsNullOrEmpty(model.Email)) throw new ArgumentException("Value cannot be null or empty.", "Email"); if (String.IsNullOrEmpty(model.Password)) throw new ArgumentException("Value cannot be null or empty.", "Password"); if (String.IsNullOrEmpty(model.InviteId)) throw new ArgumentException("Value cannot be null or empty.", "InviteId"); var selectedPricingPlanId = (int)model.SelectedPricingPlan; User user = new User() { UserName = model.Email, Password = model.Password, FirstName = model.FirstName, LastName = model.LastName, ParentUserId = model.Invitation.InvitedByUserId, PricingPlanId = selectedPricingPlanId > 0 ? selectedPricingPlanId : (int)PricingPlans.Member, HasAgreedToPrivacyPolicy = model.HasAgreedToPrivacyPolicy, HasAllowedCommunication = model.HasAllowedCommunication, SiteProfileId = model.Invitation.InvitedByUser.SiteProfileId }; try { user = AccountService.RegisterUser(user, inv.InvitationId); SetFriendlyNameCookie(user.FullName()); SetSiteProfileCookie(SiteProfileData.SiteProfile().ProfileId); UserEventLogService.LogUserEvent(UserActions.Register); FormsAuthenticationService.SignIn(user.UserName, true /* createPersistentCookie */); SessionService.Session().RefreshUser(this.UserName()); return RedirectToAction(MVC.Home.Index()); } catch (Exception ex){ Log.Error(ex); ModelState.AddModelError("Email", SystemErrors.UserCreationFailed);//AccountValidation.ErrorCodeToString(createStatus)); } break; } case (int)InvitationStatusCodes.Registered: { ModelState.AddModelError("InviteId", SystemErrors.InviteCodeAlreadyUsed); break; } case (int)InvitationStatusCodes.Expired: { ModelState.AddModelError("InviteId", SystemErrors.InviteCodeExpired); break; } } } else { ModelState.AddModelError("InviteId", SystemErrors.InviteCodeNoMatch); } } } // If we got this far, something failed, redisplay form model.NavigationLocation = new string[] { "Register" }; this.FeedbackError("There was an error registering you..."); ViewData["PasswordLength"] = AccountService.MinPasswordLength; return View(model); }