public void ChangePassword(ModelViewChangePassword model) { if (model.TokenApp != GlobalConfiguration.TokenWEB) { if (model.TokenApp != GlobalConfiguration.TokenMobile) { throw new Exception("TokenInvalid"); } } var objRepo = new RepositoryUser(); var dataUsuario = objRepo.GetToken(model.TokenUser); if (dataUsuario.Password != new BusinessCryptoMD5(GlobalConfiguration.CryptoKey).CryptoString(model.OldPassword)) { throw new Exception("PasswordOldInvalid"); } if (model.NewPassword != model.ConfirmPassword) { throw new Exception("ConfirmPassword"); } dataUsuario.Password = new BusinessCryptoMD5(GlobalConfiguration.CryptoKey).CryptoString(model.NewPassword); dataUsuario.ChangePassword = false; objRepo.Update(dataUsuario); }
public void RegisterFCM(ModelViewUserFCM model) { if (model.TokenApp != GlobalConfiguration.TokenWEB) { if (model.TokenApp != GlobalConfiguration.TokenMobile) { throw new Exception("TokenInvalid"); } } var objRepo = new RepositoryUser(); var dataUsuario = objRepo.GetToken(model.TokenUser); var dataDevice = new BusinessDevicePhone().GetByIMEI(model.IMEI); if (dataDevice != null) { dataDevice.Phone = model.Phone; dataDevice.FCM = model.TokenPush; new BusinessDevicePhone().Update(dataDevice); } else { dataDevice = new ModelViewDevicePhone() { DevicePhoneID = 0, IMEI = model.IMEI, Phone = model.Phone, FCM = model.TokenPush, Status = true, CreateDate = DateTime.UtcNow, ModifyDate = DateTime.UtcNow }; dataDevice = new BusinessDevicePhone().Register(dataDevice); } foreach (var dataDeviceUser in new BusinessDevicePhoneUser().GetByUser(dataUsuario.UserID)) { dataDeviceUser.Status = false; dataDeviceUser.ModifyDate = DateTime.UtcNow; new BusinessDevicePhoneUser().Update(dataDeviceUser); } foreach (var dataDeviceUser in new BusinessDevicePhoneUser().GetByDevicePhone(dataDevice.DevicePhoneID)) { dataDeviceUser.Status = false; dataDeviceUser.ModifyDate = DateTime.UtcNow; new BusinessDevicePhoneUser().Update(dataDeviceUser); } var dataUserDevice = new BusinessDevicePhoneUser().Get(dataDevice.DevicePhoneID, dataUsuario.UserID); if (dataUserDevice == null) { new BusinessDevicePhoneUser().Insert(new entities.ModelView.Security.ModelViewDevicePhoneUser() { UserID = dataUsuario.UserID, DevicePhoneID = dataDevice.DevicePhoneID, FCM = model.TokenPush, Status = true, CreateDate = DateTime.UtcNow, ModifyDate = DateTime.UtcNow }); } else { dataUserDevice.Status = true; dataUserDevice.ModifyDate = DateTime.UtcNow; new BusinessDevicePhoneUser().Update(dataUserDevice); } }
public ModelViewUser Insert(ModelViewUser model) { var objRepository = new RepositoryUser(); var objSecurity = new BusinessSecurity(); bool salir = false; string token = ""; while (!salir) { token = objSecurity.GenerateToken(); if (objRepository.GetToken(token) == null) { salir = true; } } string clave = objSecurity.GeneratePassword(8); if (objRepository.GetEmail(model.Email) != null) { throw new Exception("DuplicateEmail"); } if (objRepository.GetUserName(model.UserName) != null) { throw new Exception("DuplicateUser"); } EntityUser data = new EntityUser() { UserID = model.UserID, ProfileID = model.ProfileID, UserName = model.UserName, Name = model.Name, Password = new BusinessCryptoMD5(GlobalConfiguration.CryptoKey).CryptoString(clave), Token = token, ChangePassword = true, Email = model.Email, Status = true, DateLastAccess = DateTime.UtcNow, DateCreate = DateTime.UtcNow, DateModification = DateTime.UtcNow }; data = objRepository.Insert(data); model.UserID = data.UserID; List <string> arr = new List <string>(); arr.Add(model.Email); string sb = File.ReadAllText(GlobalConfiguration.LocateBodyMail + "NotificationUserBodyContent.txt"); sb = sb.Replace("#%NombreUsuario%#", data.UserName); sb = sb.Replace("#%ClaveTemporal%#", clave); sb = sb.Replace("#%Nombre%#", data.Name); //Nombre de usuario, usuario, pass, //new BusinessNotification().SendMails(arr, "Mabe - Registro de usuario ServiPlus", sb); new BusinessNotification().SendMailExchange(GlobalConfiguration.exchangeUser, GlobalConfiguration.exchangePwd, arr, "Mabe - Registro de usuario ServiPlus", sb); return(model); }