public override string[] GetAllRoles() { using (var servicios = new FrameworkServiceFactory()) { return(servicios.ServiceRole.RolesToStringArray()); } }
public static void ChangeEmail(user user, string oldEmail, string newEmail) { var result = (user != null) && (!string.IsNullOrEmpty(oldEmail)) && (!string.IsNullOrEmpty(newEmail)) && (user.Email.Equals(oldEmail, StringComparison.OrdinalIgnoreCase)); if (!result) { throw new ServiceUserException("ChangeEmail"); } using (var servicios = new FrameworkServiceFactory()) { user = servicios.ServiceUser.Find(user.Id); if (servicios.ServiceUser.AnyExceptThis(newEmail, user.Id)) { throw new ServiceUserException("Email registred"); } user.DateUpdated = DateTime.Now; user.UserUpdated = user.Id; user.Email = newEmail.ToLower(); using (var transaction = new TransactionScope()) { servicios.ServiceUser.GetOwnDataService.Update(user); transaction.Complete(); } } }
public ActionResult Index(LoginModel model, string returnUrl) { if (!ModelState.IsValid) { ModelState.AddModelError("", "ErrorInvalidInput"); } else { try { MyConstant.EnumLoginError autUser; using (var servicios = new FrameworkServiceFactory()) { var user = servicios.ServiceUser.Find(model.Email); autUser = servicios.ServiceUser.Authenticate(user, model.Password); if (autUser == MyConstant.EnumLoginError.NoError) { servicios.ServiceUser.LoginUser(user); UserContext.Login(user, false); return(RedirectToAction("RedirectToLocal", "Account", new { returnUrl })); } } switch (autUser) { case MyConstant.EnumLoginError.UserLocked: ModelState.AddModelError("", "ErrorUserLocked"); break; case MyConstant.EnumLoginError.UserConnected: ModelState.AddModelError("", "ErrorUserConnected"); break; case MyConstant.EnumLoginError.NoUserRegistered: ModelState.AddModelError("", "ErrorNoUserRegistered"); break; case MyConstant.EnumLoginError.IncorrectPassword: ModelState.AddModelError("", "ErrorIncorrectPassword"); break; case MyConstant.EnumLoginError.PasswordOlder: ModelState.AddModelError("", "ErrorPasswordOlder"); break; case MyConstant.EnumLoginError.UserWait: ModelState.AddModelError("", "ErrorUserWait"); break; } } catch (Exception e) { ModelState.AddModelError("", e.Message); } } // If we got this far, something failed, redisplay form ViewBag.ReturnUrl = returnUrl; return(View(model)); }
public static void Delete(user user) { if (user == null) { throw new ServiceUserException("Delete"); } try { using (var servicios = new FrameworkServiceFactory()) { var userId = user.Id; user = servicios.ServiceUser.Find(userId); using (var transaction = new TransactionScope()) { user.Roles.Clear(); servicios.ServiceUser.GetOwnDataService.Delete(user); transaction.Complete(); } } } catch (ApplicationException e) { throw new ServiceUserException("Delete: " + e.Message); } }
private static void OperChangePass(user user, string newPass) { bool result = (user != null) && (!string.IsNullOrEmpty(newPass)); if (!result) { throw new ServiceUserException("ChangePass"); } try { using (var servicios = new FrameworkServiceFactory()) { user = servicios.ServiceUser.Find(user.Id); user.Pass = MyCryptography.EncryptPass(newPass); user.DateLastPassChange = DateTime.Now; user.CountAfterPassAttempt = 0; using (var transaction = new TransactionScope()) { servicios.ServiceUser.GetOwnDataService.Update(user); transaction.Complete(); } } } catch (ApplicationException e) { throw new ServiceUserException("ChangePass: " + e.Message); } }
public static void UpdateUserRoles(user user, ICollection <role> roles, int userLastLockout) { try { using (var servicios = new FrameworkServiceFactory()) { user = servicios.ServiceUser.Find(user.Id); if ((roles != null) && (roles.Count > 0)) { user.Roles.Clear(); foreach (var item in roles) { user.Roles.Add(servicios.ServiceRole.Find(item.Id)); } } else { user.IsLocked = true; user.DateLastLockout = DateTime.Now; user.UserLastLockout = userLastLockout; } using (var transaction = new TransactionScope()) { servicios.ServiceUser.GetOwnDataService.Update(user); transaction.Complete(); } } } catch (ApplicationException e) { throw new ServiceUserException("UpdateUserRoles: " + e.Message); } }
public static void ChangePersonalData(user user, string name, string lastName, int idPais, string phone) { var result = (user != null) && (!string.IsNullOrEmpty(name)) && (!string.IsNullOrEmpty(lastName)) && (!string.IsNullOrEmpty(phone)) && (idPais > 0); if (!result) { throw new ServiceUserException("ChangePersonalData"); } using (var servicios = new FrameworkServiceFactory()) { user = servicios.ServiceUser.Find(user.Id); user.DateUpdated = DateTime.Now; user.UserUpdated = user.Id; user.Name = name; user.LastName = lastName; user.Phone = phone; using (var transaction = new TransactionScope()) { servicios.ServiceUser.GetOwnDataService.Update(user); transaction.Complete(); } } }
public override bool IsUserInRole(string username, string roleName) { using (var servicios = new FrameworkServiceFactory()) { var user = servicios.ServiceUser.Find(username); return(servicios.ServiceUser.IsUserInRole(user, roleName)); } }
public static user StaticFind(int id) { using (var servicios = new FrameworkServiceFactory()) { var repository = servicios.ServiceUser.Find(id); return(repository); } }
public override string[] GetRolesForUser(string username) { using (var servicios = new FrameworkServiceFactory()) { var user = servicios.ServiceUser.Find(username); return(servicios.ServiceUser.RolesToStringArray(user)); } }
public static void StoreAuthenticationData(user user) { using (var servicios = new FrameworkServiceFactory()) { user = servicios.ServiceUser.Find(user.Id); var userData = user.Id + ";" + servicios.ServiceUser.RolesToString(user); var ticket = new FormsAuthenticationTicket(1, string.Format("{0}", user.Email), DateTime.Now, DateTime.Now.AddMinutes(30), true, userData, FormsAuthentication.FormsCookiePath); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket)); HttpContext.Current.Response.Cookies.Add(cookie); } }
public static void ResetPass(user user, string newPass, int userResetPass) { var result = (user != null) && (!string.IsNullOrEmpty(newPass)); if (!result) { throw new ServiceUserException("ResetPass"); } using (var servicios = new FrameworkServiceFactory()) { user = servicios.ServiceUser.Find(user.Id); user.UserResetPass = userResetPass; user.DateResetPass = DateTime.Now; using (var transaction = new TransactionScope()) { servicios.ServiceUser.ChangePass(user, newPass); transaction.Complete(); } } }
public static void DesconnectedUser(int idCurrentUser) { try { using (var servicios = new FrameworkServiceFactory()) { var user = servicios.ServiceUser.Find(idCurrentUser); if (user != null) { user.IsConnected = false; using (var transaction = new TransactionScope()) { servicios.ServiceUser.GetOwnDataService.Update(user); transaction.Complete(); } } } } catch (ApplicationException e) { throw new ServiceUserException("DesconnectedUser: " + e.Message); } }
public static void ChangeLocked(user user, int userLastLockout) { var result = (user != null); if (!result) { throw new ServiceUserException("ChangeLocked"); } try { using (var servicios = new FrameworkServiceFactory()) { user = servicios.ServiceUser.Find(user.Id); if (user.IsLocked) { user.IsLocked = false; user.CountFailedPassAttempt = 0; } else { user.IsLocked = true; } user.DateLastLockout = DateTime.Now; user.UserLastLockout = userLastLockout; using (var transaction = new TransactionScope()) { servicios.ServiceUser.GetOwnDataService.Update(user); transaction.Complete(); } } } catch (ApplicationException e) { throw new ServiceUserException("ChangeLocked: " + e.Message); } }
protected AbstractService(FrameworkServiceFactory serviceFactory) { _serviceFactory = serviceFactory; }
public ServiceUser(FrameworkServiceFactory serviceFactory) : base(serviceFactory) { OwnDataService = new DataServiceUser(MyDataServiceFactory); }
public ServiceAdmin(FrameworkServiceFactory serviceFactory) : base(serviceFactory) { OwnDataService = new DataServiceWorker(MyDataServiceFactory); }