public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { if (!Membership.ValidateUser(model.UserName, model.Password)) { ModelState.AddModelError("", "The user name or password provided is incorrect."); return(View(model)); } else { FormsAuthentication.SetAuthCookie(model.UserName, false); ProfileBase profile = ProfileBase.Create(model.UserName); string BranchID = profile.GetPropertyValue("BranchID").ToString(); string DepartmentID = profile.GetPropertyValue("DepartmentID").ToString(); Session.Add("UserName", model.UserName); Session.Add("BranchID", BranchID); Session.Add("DepartmentID", DepartmentID); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home")); } } } return(View(model)); }
public ActionResult Edit(EditUserModel user, FormCollection collection) { if (ModelState.IsValid) { User actualUser = user.Save(_memberShipFactory); if (ProfileManager.Enabled) { ProfileBase profile = ProfileBase.Create(actualUser.LoginId, true); IEnumerator properites = ProfileBase.Properties.GetEnumerator(); if (properites != null) { while (properites.MoveNext()) { var property = properites.Current as SettingsProperty; string v = collection[property.Name]; profile[property.Name] = v; } profile.Save(); } } return(RedirectToAction("Index")); } return(View(user)); }
public override bool ValidateUser(string username, string password) { if (!base.ValidateUser(username, password)) { return(false); } // If authentication of all users are configured var user = Membership.GetUser(username); if (user == null) { return(false); } var profile = ProfileBase.Create(user.UserName); var license = ((DateTime)profile.GetPropertyValue("License")); //Licensstyrning. En licens räcker ett år. Bortser från administratörer. if (Roles.IsUserInRole(user.UserName, "admin") || license.AddYears(1) > DateTime.Now) { return(true); } else { return(false); } }
public override void Update() { _BaslangicTarihi = OwnerPage.BaslangicTarihi; _BitisTarihi = OwnerPage.BitisTarihi; ProfileBase curProfile = ProfileBase.Create(Membership.GetUser().UserName); string BayiID = curProfile.GetPropertyValue("BayiID").ToString(); if (Roles.GetRolesForUser(Membership.GetUser().UserName)[0].ToString() == "PersonelYonetici") { if (BayiID == null || BayiID == "" || BayiID == "130" || BayiID == "140") //if ile yönetici yetkisi roles dan kontrol edip -1 göndermek lazım. { BayiID = "-1"; } } var listPivot = db.S_HedefSatisDurumuPivot(Convert.ToInt32(BayiID), _BaslangicTarihi, _BitisTarihi).ToList(); if (listPivot.Count > 0) { PivotGrid.DataSource = listPivot; PivotGrid.DataBind(); } else { PivotGrid.DataSource = null; PivotGrid.DataBind(); } }
public void AuthenticatedStringProperty() { ProfileBase profile = ProfileBase.Create("foo", true); ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider); profile["Name"] = "Fred Flintstone"; profile.Save(); SettingsPropertyCollection getProps = new SettingsPropertyCollection(); SettingsProperty getProp1 = new SettingsProperty("Name"); getProp1.PropertyType = typeof(String); getProps.Add(getProp1); MySQLProfileProvider provider = InitProfileProvider(); SettingsContext ctx = new SettingsContext(); ctx.Add("IsAuthenticated", true); ctx.Add("UserName", "foo"); SettingsPropertyValueCollection getValues = provider.GetPropertyValues(ctx, getProps); Assert.AreEqual(1, getValues.Count); SettingsPropertyValue getValue1 = getValues["Name"]; Assert.AreEqual("Fred Flintstone", getValue1.PropertyValue); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["id"] != null) { if (User.IsInRole("Admin") || User.IsInRole("Dealer")) { DataList1.DataSource = SqlDataSource1; Profile = ProfileBase.Create(Membership.GetUser().UserName); } else if (User.IsInRole("Member")) { DataList1.DataSource = SqlDataSource2; Profile = ProfileBase.Create(Membership.GetUser().UserName); } else { DataList1.DataSource = SqlDataSource3; Profile = ProfileBase.Create("Guest"); } Profile.Save(); DataList1.DataBind(); } else { noItemLabel.Text = "Please go back to the products or specials page and select an item to view"; addToCartButton.Visible = false; } }
public ActionResult Register(RegisterModel registerModel) { if (ModelState.IsValid) { // Попытка зарегистрировать пользователя try { Membership.CreateUser(registerModel.UserName, registerModel.Password); ProfileBase profile = ProfileBase.Create(registerModel.UserName); profile.SetPropertyValue("Name", registerModel.Name); profile.SetPropertyValue("Surname", registerModel.Surname); profile.SetPropertyValue("Patronymic", registerModel.Patronymic); profile.SetPropertyValue("Email", registerModel.Email); profile.SetPropertyValue("UserName", registerModel.UserName); profile.Save(); Roles.AddUserToRole(registerModel.UserName, "Member"); EmailServices.SendEmail(registerModel); return(RedirectToAction("RegisterContinue", "Account", new { username = registerModel.UserName })); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // Появление этого сообщения означает наличие ошибки; повторное отображение формы return(View(registerModel)); }
protected void BindGrid() { var urun = db.S_Urunler().ToList(); if (urun.Count > 0) { GridViewDataComboBoxColumn combo = EmployeesGrid.Columns["UrunID"] as GridViewDataComboBoxColumn; combo.PropertiesComboBox.ValueType = typeof(int); combo.PropertiesComboBox.DataSource = urun; } var tip = db.S_Tip(6).ToList(); if (tip.Count > 0) { GridViewDataComboBoxColumn combo = EmployeesGrid.Columns["Onay"] as GridViewDataComboBoxColumn; combo.PropertiesComboBox.ValueType = typeof(int); combo.PropertiesComboBox.DataSource = tip; } ProfileBase curProfile = ProfileBase.Create(Membership.GetUser().UserName); string bayiid = curProfile.GetPropertyValue("BayiID").ToString(); var list = db.S_Siparislerim(Convert.ToInt32(bayiid)).ToList(); if (list.Count > 0) { EmployeesGrid.DataSource = list; EmployeesGrid.DataBind(); } }
public User GetUser(string userName) { // this is replaced with claims string[] roles = Roles.GetRolesForUser(); // var attributes = SimulatedLdapProfileStore.GetAttributesFor(userName, new[] { "costCenter", "manager", "displayName" }); // we still use profile for app-specific profile data like preferred reiumbursment method var profile = ProfileBase.Create(userName); var user = new User { CostCenter = profile.GetProperty <string>("CostCenter"), FullName = profile.GetProperty <string>("FirstName") + " " + profile.GetProperty <string>("LastName"), Manager = profile.GetProperty <string>("Manager"), UserName = Membership.GetUser().UserName, PreferredReimbursementMethod = string.IsNullOrEmpty(profile.GetProperty <string>("PreferredReimbursementMethod")) ? ReimbursementMethod.NotSet : (ReimbursementMethod) Enum.Parse(typeof(ReimbursementMethod), profile.GetProperty <string>("PreferredReimbursementMethod")), Roles = new List <string>(roles) }; return(user); }
/// <summary> /// Adds a new user to the SQL Server membership database. /// </summary> /// <param name="username">The user name for the new user.</param> /// <param name="password">The password for the new user.</param> /// <param name="email">The e-mail address for the new user.</param> /// <param name="passwordQuestion">The password question for the new user.</param> /// <param name="passwordAnswer">The password answer for the new user.</param> /// <param name="isApproved">Whether or not the new user is approved to be validated.</param> /// <param name="providerUserKey">A <see cref="T:System.Guid"></see> that uniquely identifies the membership user in the SQL Server database.</param> /// <param name="status">One of the <see cref="T:System.Web.Security.MembershipCreateStatus"></see> values, indicating whether the user was created successfully.</param> /// <returns> /// A <see cref="T:System.Web.Security.MembershipUser"></see> object for the newly created user. If no user was created, this method returns null. /// </returns> public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { MembershipUser oldUser = base.CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey, out status); if (status == MembershipCreateStatus.Success) { ProfileBase profile = ProfileBase.Create(oldUser.UserName); string firstName = (string)profile.GetPropertyValue("FirstName"); string lastName = (string)profile.GetPropertyValue("LastName"); string displayName = (string)profile.GetPropertyValue("DisplayName"); CustomMembershipUser newUser = new CustomMembershipUser(oldUser.ProviderName, oldUser.UserName, oldUser.ProviderUserKey, oldUser.Email, oldUser.PasswordQuestion, oldUser.Comment, oldUser.IsApproved, oldUser.IsLockedOut, oldUser.CreationDate, oldUser.LastLoginDate, oldUser.LastActivityDate, oldUser.LastPasswordChangedDate, oldUser.LastLockoutDate, displayName, firstName, lastName); return(newUser); } return(null); }
/// <summary> /// Returns information from the SQL Server membership database for a user and provides an option to update the last activity date/time stamp for the user. /// </summary> /// <param name="username">The name of the user to get information for.</param> /// <param name="userIsOnline">true to update the last activity date/time stamp for the user; false to return user information without updating the last activity date/time stamp for the user.</param> /// <returns> /// A <see cref="T:System.Web.Security.MembershipUser"></see> object representing the specified user. If no user is found in the database for the specified username value, null is returned. /// </returns> /// <exception cref="T:System.ArgumentException">username exceeds 256 characters.- or -username contains a comma.</exception> /// <exception cref="T:System.ArgumentNullException">username is null.</exception> public override MembershipUser GetUser(string username, bool userIsOnline) { MembershipUser oldUser = base.GetUser(username, userIsOnline); if (oldUser == null) { return(null); } ProfileBase profile = ProfileBase.Create(username); string firstName = (string)profile.GetPropertyValue("FirstName"); string lastName = (string)profile.GetPropertyValue("LastName"); string displayName = (string)profile.GetPropertyValue("DisplayName"); CustomMembershipUser newUser = new CustomMembershipUser(oldUser.ProviderName, oldUser.UserName, oldUser.ProviderUserKey, oldUser.Email, oldUser.PasswordQuestion, oldUser.Comment, oldUser.IsApproved, oldUser.IsLockedOut, oldUser.CreationDate, oldUser.LastLoginDate, oldUser.LastActivityDate, oldUser.LastPasswordChangedDate, oldUser.LastLockoutDate, displayName, firstName, lastName); return(newUser); }
/// <summary> /// Returns a collection of membership users for which the e-mail address field contains the specified e-mail address. /// </summary> /// <param name="emailToMatch">The e-mail address to search for.</param> /// <param name="pageIndex">The index of the page of results to return. pageIndex is zero-based.</param> /// <param name="pageSize">The size of the page of results to return.</param> /// <param name="totalRecords">The total number of matched users.</param> /// <returns> /// A <see cref="T:System.Web.Security.MembershipUserCollection"></see> that contains a page of pageSize<see cref="T:System.Web.Security.MembershipUser"></see> objects beginning at the page specified by pageIndex. /// </returns> /// <exception cref="T:System.ArgumentException">emailToMatch is longer than 256 characters.- or -pageIndex is less than zero.- or -pageSize is less than one.- or -pageIndex multiplied by pageSize plus pageSize minus one exceeds <see cref="F:System.Int32.MaxValue"></see>.</exception> public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords) { MembershipUserCollection collection = new MembershipUserCollection(); CustomMembershipUser newUser; foreach (MembershipUser oldUser in base.FindUsersByEmail(emailToMatch, pageIndex, pageSize, out totalRecords)) { ProfileBase profile = ProfileBase.Create(oldUser.UserName); string firstName = (string)profile.GetPropertyValue("FirstName"); string lastName = (string)profile.GetPropertyValue("LastName"); string displayName = (string)profile.GetPropertyValue("DisplayName"); newUser = new CustomMembershipUser(oldUser.ProviderName, oldUser.UserName, oldUser.ProviderUserKey, oldUser.Email, oldUser.PasswordQuestion, oldUser.Comment, oldUser.IsApproved, oldUser.IsLockedOut, oldUser.CreationDate, oldUser.LastLoginDate, oldUser.LastActivityDate, oldUser.LastPasswordChangedDate, oldUser.LastLockoutDate, displayName, firstName, lastName); collection.Add(newUser); } return(collection); }
protected void showBtn_Click(object sender, EventArgs e) { ProfileBase profile = ProfileBase.Create(nametextBox.Text); emailTextBox.Text = profile.GetPropertyValue("Email").ToString(); birthdayCalendar.SelectedDate = (DateTime)profile.GetPropertyValue("Birthday"); }
protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack || Membership.GetUser("test") != null) { return; } // Создаем пользователя MembershipCreateStatus createStatus; /*var membershipUser = */ Membership.CreateUser("test", "test99!", "", "Why should you not panic?", "This is only a test.", true, out createStatus); if (createStatus != MembershipCreateStatus.Success) { info.InnerHtml = string.Format("Attempt to create user \"test\" failed with {0}", createStatus); } // Помещаем пользователя в хранилище ролей if (!Roles.RoleExists("Administrator")) { Roles.CreateRole("Administrator"); Roles.AddUserToRole("test", "Administrator"); } // Инициализируем параметры профиля var profileBase = ProfileBase.Create("test"); profileBase["FirstName"] = "Tester"; profileBase["LastName"] = "Smith"; profileBase["CustomerCode"] = "540-SLJTE"; profileBase.Save(); }
protected virtual IEnumerable <Claim> GetProfileClaims(string userName) { var claims = new List <Claim>(); if (ProfileManager.Enabled) { var profile = ProfileBase.Create(userName, true); if (profile != null) { foreach (SettingsProperty prop in ProfileBase.Properties) { object value = profile.GetPropertyValue(prop.Name); if (value != null) { if (!string.IsNullOrWhiteSpace(value.ToString())) { claims.Add(new Claim(GetProfileClaimType(prop.Name.ToLowerInvariant()), value.ToString())); } } } } } return(claims); }
public void UpdateUserPreferredReimbursementMethod(User user) { var profile = ProfileBase.Create(user.UserName); profile.SetPropertyValue("PreferredReimbursementMethod", Enum.GetName(typeof(ReimbursementMethod), user.PreferredReimbursementMethod)); profile.Save(); }
public User GetUser(string userName, bool throwOnError = true) { Guard.ArgumentNotNullOrEmpty(userName, "userName"); return(exManager.Process(() => { var membershipUser = Membership.GetUser(userName); if (membershipUser == null) { if (throwOnError) { throw new InvalidOperationException(Properties.Resources.MembershipUserNotFound); } return null; } var attributes = profileStore.GetAttributesFor(userName, new[] { "costCenter", "manager", "displayName" }); var user = this.container.Resolve <User>(); user.Roles = Roles.GetRolesForUser(userName); user.CostCenter = attributes["costCenter"]; user.FullName = attributes["displayName"]; user.Manager = attributes["manager"]; // TracingBehavior should trigger here user.UserName = membershipUser.UserName; var profile = ProfileBase.Create(userName); user.PreferredReimbursementMethod = string.IsNullOrEmpty(profile.GetProperty <string>("PreferredReimbursementMethod")) ? ReimbursementMethod.NotSet : (ReimbursementMethod)Enum.Parse(typeof(ReimbursementMethod), profile.GetProperty <string>("PreferredReimbursementMethod")); return user; }, Constants.NotifyPolicy)); }
public ActionResult RenameExternalSource(string id, string newname) { foreach (MembershipUser user in Membership.GetAllUsers()) { KcsarUserProfile profile = ProfileBase.Create(user.UserName) as KcsarUserProfile; List <string> external = profile.ExternalSource.Split(',').Select(f => f.Trim()).ToList(); int idx = external.IndexOf(id); if (idx >= 0) { if (string.IsNullOrWhiteSpace(newname)) { external.Remove(id); } else { external[idx] = newname; } profile.ExternalSource = string.Join(",", external.ToArray()); profile.Save(); } } return(new ContentResult { Content = "Done" }); }
private void writeProfileButton_Click(object sender, System.EventArgs e) { if (this.identity != null) { if (this.profile != null) { this.profileForm.Profile.FirstName = this.profile.FirstName; this.profileForm.Profile.LastName = this.profile.LastName; this.profileForm.Profile.Theme = this.profile.Theme; } DialogResult result = this.profileForm.ShowDialog(); if (result == DialogResult.OK) { this.Cursor = Cursors.WaitCursor; this.profile = this.profileForm.Profile; // Write the profile to the configured ASP.NET Profile provider ProfileBase userProfile = ProfileBase.Create(this.identity.Name); userProfile["FirstName"] = this.profile.FirstName; userProfile["LastName"] = this.profile.LastName; userProfile["Theme"] = this.profile.Theme; userProfile.Save(); this.DisplayProfileResults(string.Format(Properties.Resources.ProfileUpdatedMessage, this.identity.Name)); this.Cursor = Cursors.Arrow; } } else { this.DisplayProfileResults(Properties.Resources.NullIdentityMessage); } }
/// <summary> /// Adds a new user to the system. /// </summary> /// <param name="displayName">name to display for the user, can be null</param> /// <param name="active">is the account active</param> /// <param name="created">account creation datetime</param> /// <returns></returns> public UserInfo AddUser(string username, string displayName, string password, string email, bool active, DateTime created) { if (string.IsNullOrEmpty(username)) { throw new ArgumentNullException(nameof(username)); } if (string.IsNullOrEmpty(password)) { throw new ArgumentNullException(nameof(password)); } if (string.IsNullOrEmpty(email)) { throw new ArgumentNullException(nameof(email)); } MembershipCreateStatus createStatus; var membershipUser = Membership.CreateUser(username, password, email, null, null, active, out createStatus); switch (createStatus) { case MembershipCreateStatus.DuplicateEmail: case MembershipCreateStatus.DuplicateProviderUserKey: case MembershipCreateStatus.DuplicateUserName: case MembershipCreateStatus.UserRejected: return(null); } var profile = ProfileBase.Create(membershipUser.UserName); profile["DisplayName"] = displayName; profile.Save(); return(ToUserInfo(membershipUser)); }
public ActionResult SetRole(AjaxEmployee model) { if (ModelState.IsValid) { var s = CH.GetDataById <EmployeeRole>(model.ID); s.IsActivated = model.IsActivated; s.RoleID = model.RoleID; s.ExpLevelID = model.ExpLevelID; s.StartDate = model.StartDate; s.IsTrainee = model.IsTrainee; //MembershipUser user = Membership.GetUser(s.AccountName); ProfileBase objProfile = ProfileBase.Create(s.AccountName); objProfile.SetPropertyValue("IsActivated", model.IsActivated); objProfile.Save(); CH.Edit <EmployeeRole>(s); return(Json("")); } else { string error = ""; foreach (var key in ModelState.Keys) { var state = ModelState[key]; if (state.Errors.Any()) { error += state.Errors.First().ErrorMessage + ","; } } return(Json(error.Substring(0, error.Length - 1))); } }
public override bool UserCanReceiveNotification(MembershipUser user) { if (Enabled == false) { return(false); } if (user == null) { throw new ArgumentNullException("user"); } if (string.IsNullOrEmpty(user.Email)) { return(false); } else { ProfileBase profile = ProfileBase.Create(user.UserName); object profReceiveNotification = profile[PROFILE_RECEIVENOTIFICATION]; if (profReceiveNotification is bool) { return((bool)profReceiveNotification); } else { return(false); } } }
public void AuthenticatedDateTime() { ProfileBase profile = ProfileBase.Create("foo", true); ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider); DateTime date = DateTime.Now; profile["BirthDate"] = date; profile.Save(); SettingsPropertyCollection getProps = new SettingsPropertyCollection(); SettingsProperty getProp1 = new SettingsProperty("BirthDate"); getProp1.PropertyType = typeof(DateTime); getProp1.SerializeAs = SettingsSerializeAs.Xml; getProps.Add(getProp1); MySQLProfileProvider provider = InitProfileProvider(); SettingsContext ctx = new SettingsContext(); ctx.Add("IsAuthenticated", true); ctx.Add("UserName", "foo"); SettingsPropertyValueCollection getValues = provider.GetPropertyValues(ctx, getProps); Assert.AreEqual(1, getValues.Count); SettingsPropertyValue getValue1 = getValues["BirthDate"]; Assert.AreEqual(date, getValue1.PropertyValue); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.Email, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { ProfileBase profile = ProfileBase.Create(model.Email); profile["BirthDate"] = model.BirthDate; profile["Gender"] = model.Gender; profile["Name"] = model.Name; profile["LastName"] = model.LastName; profile["CPF"] = model.CPF; profile.Save(); FormsAuthentication.SetAuthCookie(model.Email, false /* createPersistentCookie */); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return(View(model)); }
public void GetAllProfiles() { ProfileBase profile = ProfileBase.Create("foo", true); ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider); profile["Name"] = "Fred Flintstone"; profile.Save(); SettingsPropertyCollection getProps = new SettingsPropertyCollection(); SettingsProperty getProp1 = new SettingsProperty("Name"); getProp1.PropertyType = typeof(String); getProps.Add(getProp1); MySQLProfileProvider provider = InitProfileProvider(); SettingsContext ctx = new SettingsContext(); ctx.Add("IsAuthenticated", true); ctx.Add("UserName", "foo"); int total; ProfileInfoCollection profiles = provider.GetAllProfiles( ProfileAuthenticationOption.All, 0, 10, out total); Assert.AreEqual(1, total); }
protected void Page_Load(object sender, EventArgs e) { QHSEEntities context = new QHSEEntities(); IIdentity id = User.Identity; dynamic profile = ProfileBase.Create(id.Name); Session["username"] = profile.username; if (User.IsInRole("Admin") || User.IsInRole("Sub-Admin")) { Response.Redirect("~/Admin/ReportList.aspx"); } else if (User.IsInRole("User")) { Response.Redirect("~/Users/ObservationList.aspx"); } else { Response.Write("User doesn't have a role, please log in again"); } //else //{ // Response.Write("User doesn't have a role, please log in again"); // Response.Redirect("~/Login.aspx"); //} }
public ActionResult Index(RegisterViewModel model) { if (ModelState.IsValid) { UIUserCreateStatus status; IEnumerable <string> errors = Enumerable.Empty <string>(); var result = UIUserProvider.CreateUser(model.Username, model.Password, model.Email, null, null, true, out status, out errors); if (status == UIUserCreateStatus.Success) { UIRoleProvider.CreateRole(AdminRoleName); UIRoleProvider.AddUserToRoles(result.Username, new string[] { AdminRoleName }); if (ProfileManager.Enabled) { var profile = EPiServerProfile.Wrap(ProfileBase.Create(result.Username)); profile.Email = model.Email; profile.Save(); } AdministratorRegistrationPage.IsEnabled = false; SetFullAccessToWebAdmin(); var resFromSignIn = UISignInManager.SignIn(UIUserProvider.Name, model.Username, model.Password); if (resFromSignIn) { return(Redirect(UrlResolver.Current.GetUrl(ContentReference.StartPage))); } } AddErrors(errors); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Profile(ViewModels.Account.ProfileViewModel viewModel) { if (ModelState.IsValid) { bool update = false; dynamic profile; profile = ProfileBase.Create(Membership.GetUser().UserName); if (viewModel.ContactId != null && viewModel.ContactId.HasValue) { profile.ContactId = viewModel.ContactId.Value.ToString(); update = true; } else { profile.ContactId = ""; update = true; } if (!string.IsNullOrEmpty(viewModel.ExternalAppKey)) { profile.ExternalAppKey = viewModel.ExternalAppKey; update = true; } if (update) { profile.Save(); } } return(RedirectToAction("Index", "Home")); }
public ActionResult Index(RegisterViewModel model) { if (ModelState.IsValid) { UIUserCreateStatus status; IEnumerable <string> errors = Enumerable.Empty <string>(); var result = _UIUserProvider.CreateUser(model.Username, model.Password, model.Email, null, null, true, out status, out errors); if (status == UIUserCreateStatus.Success) { //Check if role exists, if it does not create it and set full permission to all pages of the site SetFullAccessToRole(AdminRoleName); //Add the newly created user to the role. _UIRoleProvider.AddUserToRoles(result.Username, new string[] { AdminRoleName }); if (ProfileManager.Enabled) { var profile = EPiServerProfile.Wrap(ProfileBase.Create(result.Username)); profile.Email = model.Email; profile.Save(); } //After user creation, sign-in the user account and redirect to Episerver CMS var resFromSignIn = _UISignInManager.SignIn(_UIUserProvider.Name, model.Username, model.Password); if (resFromSignIn) { return(Redirect("/episerver/cms")); } } AddErrors(errors); } // If we got this far, something failed, redisplay form return(View(_ViewPath, model)); }
protected void Page_Load(object sender, EventArgs e) { IIdentity id = User.Identity; dynamic profile = ProfileBase.Create(id.Name); //Session["username"] = profile.username; if (User.IsInRole("Admin") || User.IsInRole("Sub-Admin")) { Response.Redirect("~/Admin/QuizResultList.aspx"); } else if (User.IsInRole("Hub")) { Response.Redirect("~/Hub/QuizList.aspx"); } else { Response.Write("User doesn't have a role, please log in again"); } //else //{ // Response.Write("User doesn't have a role, please log in again"); // Response.Redirect("~/Login.aspx"); //} }