public ActionResult Login() { try { GetUserProfileObject PostDataArrived = CS.GetPostData <GetUserProfileObject>(this.Request); ConnectionStringSettings connectionStringSetting = ConfigurationManager.ConnectionStrings["ISTATWebClientSSO"]; if (connectionStringSetting == null || string.IsNullOrEmpty(connectionStringSetting.ConnectionString)) { throw new Exception("ConnectionString not set"); } if (PostDataArrived.IsSuperAdmin) { UserRolesEnum ruolo = UserRolesEnum.Administrator; PostDataArrived.UserRole = new UserRoleObject() { RoleId = (int)ruolo, Role = ruolo.ToString() }; } else { connectionStringSetting = ConfigurationManager.ConnectionStrings["ISTATWebClientConnection"]; ProfileWidget pw = new ProfileWidget(connectionStringSetting.ConnectionString); PostDataArrived.UserRole = pw.GetRole(PostDataArrived); } Session[ProfileSession] = PostDataArrived; return(CS.ReturnForJQuery(new JavaScriptSerializer().Serialize(PostDataArrived))); } catch (Exception ex) { return(CS.ReturnForJQuery(ex.Message)); } }
public ActionResult ModUserRole() { GetUserProfileObject PostDataArrived = CS.GetPostData <GetUserProfileObject>(this.Request); if (Session[ProfileSession] == null) { throw new Exception("No logged user"); } GetUserProfileObject LoggedUser = (GetUserProfileObject)Session[ProfileSession]; if (LoggedUser.UserRole != null && (UserRolesEnum)LoggedUser.UserRole.RoleId != WidgetComplements.Model.Enum.UserRolesEnum.Administrator) { throw new Exception("No Administration user"); } ConnectionStringSettings connectionStringSetting = ConfigurationManager.ConnectionStrings["ISTATWebClientConnection"]; if (connectionStringSetting == null || string.IsNullOrEmpty(connectionStringSetting.ConnectionString)) { throw new Exception("ConnectionString not set"); } ProfileWidget pw = new ProfileWidget(connectionStringSetting.ConnectionString); PostDataArrived = pw.ChangeRole(PostDataArrived); return(CS.ReturnForJQuery(new JavaScriptSerializer().Serialize(PostDataArrived))); }
/// <summary> /// Saves the widget. /// </summary> /// <param name="model">The model.</param> /// <returns></returns> public static ProfileWidgetEditModel SaveWidget(ProfileWidgetEditModel model) { var widgetService = ServiceLocator.Current.GetInstance <IProfileWidgetService>(); var widget = new ProfileWidget(); if (model.Id > 0) { widget = widgetService.Find(model.Id); } var viewModel = model.MapTo(widget); if (widget != null) { widgetService.Save(viewModel); } return(new ProfileWidgetEditModel().MapFrom(viewModel)); }
public ActionResult GetUserList() { /*string SingleSignOnConf; * using (Stream receiveStream = this.Request.InputStream) * using (StreamReader readStream = new StreamReader(receiveStream, this.Request.ContentEncoding)) * { * SingleSignOnConf = readStream.ReadToEnd(); * } */ if (Session[ProfileSession] == null) { throw new Exception("No logged user"); } GetUserProfileObject LoggedUser = (GetUserProfileObject)Session[ProfileSession]; if (LoggedUser.UserRole != null && (UserRolesEnum)LoggedUser.UserRole.RoleId != WidgetComplements.Model.Enum.UserRolesEnum.Administrator) { throw new Exception("No Administration user"); } ConnectionStringSettings connectionStringSetting = ConfigurationManager.ConnectionStrings["ISTATWebClientConnection"]; if (connectionStringSetting == null || string.IsNullOrEmpty(connectionStringSetting.ConnectionString)) { throw new Exception("ConnectionString not set"); } ProfileWidget pw = new ProfileWidget(connectionStringSetting.ConnectionString); //Prendo tutti gli utenti su SingleSignON //Prendo tutti i Ruoli dal localDB //var JsonRet = new { UserList = pw.GetUserList(SingleSignOnConf), Roles = pw.GetRoles() }; SingleSignONService ssoService = new SingleSignONService(); var JsonRet = new { UserList = ssoService.GetUserList(), Roles = pw.GetRoles() }; return(CS.ReturnForJQuery(new JavaScriptSerializer().Serialize(JsonRet))); }
/// <summary> /// Registers the user. /// </summary> /// <param name="model">The model.</param> /// <param name="collection">The collection.</param> /// <param name="userProfile">The user profile.</param> /// <param name="currentUser">The current user.</param> /// <param name="widget">The widget.</param> /// <param name="user">The user.</param> /// <returns></returns> public static bool SaveUser(ProfileWidgetViewModel model, FormCollection collection, UserProfile userProfile, ICorePrincipal currentUser, ProfileWidget widget, out User user) { user = null; var isSuccess = true; if (currentUser == null) { return(false); } var userService = ServiceLocator.Current.GetInstance <IUserService>(); user = userService.Find(currentUser.PrincipalId); if (user == null) { return(false); } if (widget.DisplayMode != ProfileWidgetDisplayMode.ProfileDetails) { model.MapTo(user); userService.SetPassword(user, model.Password); isSuccess = userService.Save(user); } if (isSuccess && widget.DisplayMode != ProfileWidgetDisplayMode.CommonDetails) { if (userProfile != null) { foreach (var item in userProfile.ProfileType.ProfileHeaders) { foreach (var element in item.ProfileElements) { var elementName = String.Format("{0}_{1}", (ElementType)element.Type, element.Id); var value = collection[elementName]; var existingValue = userProfile.ProfileElements.FirstOrDefault(el => el.ProfileElement.Id == element.Id); if (existingValue != null) { existingValue.Value = value; } else { userProfile.ProfileElements.Add(new UserProfileElement { UserProfile = userProfile, ProfileElement = element, Value = value }); } } } var userProfileService = ServiceLocator.Current.GetInstance <IUserProfileService>(); isSuccess = userProfileService.Save(userProfile); } } return(isSuccess); }