public List <MUserVM> ReadListUser(ref string message) { List <MUserVM> lstRet = new List <MUserVM>(); MUserRPO usrRPO = new MUserRPO(imap_); TUserRoleRPO tusrRoleRPO = new TUserRoleRPO(imap_); usrRPO.BeginTrans(); if (usrRPO.ReadList(ref exec)) { tusrRoleRPO.SetObjConn(usrRPO.ObjConn); foreach (var _objUser in usrRPO.Result.Collection) { tusrRoleRPO.Conditions(nameof(TuserRole.Username), Operator.Equals(_objUser.Username)); //tusrRoleRPO.Where(nameof(TUserRole.Username)).Equals(_objUser.Username); if (tusrRoleRPO.ReadList(ref exec)) { _objUser.Password = ""; lstRet.Add(new MUserVM() { objUser = _objUser, ListRole = tusrRoleRPO.Result.Collection }); } else { break; } } } message = exec.Message; usrRPO.EndTrans(exec); return(lstRet); }
public string LockAccount(string username, string password) { MUserRPO muserRPO = new MUserRPO(imap_); muserRPO.Conditions(nameof(MUser.Username), Operator.Equals(username)); if (muserRPO.ReadOne(ref exec) && muserRPO.Result.AffectedRow > 0) { string encryptedPass = muserRPO.Result.Row.Password; if (Helpers.Crypto.ValidateKey(password, encryptedPass)) { muserRPO.Result.Row.IsLocked = true; if (muserRPO.Update(muserRPO.Result.Row, ref exec)) { return(""); } else { return(exec.Message); } } else { return("Incorrect Username or Password"); } } else { return(exec.Message); } }
private string AddOrUpdateUser(bool isUpdate, MUserVM objMuservm, string ConfirmationPassword = "") { MUserRPO muserRPO = new MUserRPO(imap_); MUser objMuser = objMuservm.objUser; string message = ""; bool validPass = objMuser.Password.Any(c => char.IsLetter(c)) && objMuser.Password.Any(c => char.IsDigit(c)); message = validPass ? "" : "Password must contain at least one letter and one numeric digit"; validPass = objMuser.Password == ConfirmationPassword; message = validPass ? "" : "Password didn't match"; if (validPass) { objMuser.Password = Helpers.Crypto.EncryptPassword(objMuser.Password); if (objMuser.Password == "") { //todo log return("Error Encrypt"); } muserRPO.BeginTrans(); if (isUpdate) { muserRPO.Conditions(nameof(objMuser.IsActive), Operator.Equals("true")); muserRPO.Update(objMuser, ref exec); AddUpdateUserRole(isUpdate, objMuservm, muserRPO.ObjConn, ref exec); } else { muserRPO.Conditions(nameof(objMuser.Username), Operator.Equals(objMuser.Username)); if (muserRPO.ReadList(ref exec)) { if (muserRPO.Result.AffectedRow > 0) { message = "username already Exist!"; } else { muserRPO.Insert(objMuser, ref exec); AddUpdateUserRole(isUpdate, objMuservm, muserRPO.ObjConn, ref exec); } } } message = exec.Message; muserRPO.EndTrans(exec); } return(message); }
public MUserVM Login(string username, string password, out string message) { string encodedPassFromDB; bool matchPass = false; MUser objRetUser = new MUser(); MUserVM objUser = new MUserVM(); MUserRPO muserRPO = new MUserRPO(imap_); Conditions cnd = new Conditions(); cnd.AddFilter(nameof(MUser.Username), Operator.Equals(username)); cnd.AddFilter(nameof(MUser.IsActive), Operator.Equals(1)); cnd.AddFilter(nameof(MUser.IsLocked), Operator.Equals(0)); muserRPO.Conditions(cnd); //muserRPO.Where(nameof(MUser.IsActive)).Equals(1); //muserRPO.Where(nameof(MUser.IsLocked)).Equals(0); if (muserRPO.ReadOne(ref exec) && muserRPO.Result.AffectedRow > 0) { encodedPassFromDB = muserRPO.Result.Row.Password; matchPass = Helpers.Crypto.ValidateKey(password, encodedPassFromDB); objRetUser = matchPass ? muserRPO.Result.Row : null; if (matchPass) { objUser.objUser = objRetUser; objUser.ListRole = new List <TuserRole>(); TUserRoleRPO objUrole = new TUserRoleRPO(imap_); objUrole.Conditions(nameof(TuserRole.Username), Operator.Equals(objRetUser.Username)); //objUrole.Where(nameof(TUserRole.Username)).Equals(objRetUser.Username); if (objUrole.ReadList(ref exec)) { objUser.ListRole = objUrole.Result.Collection; } message = exec.Message; } else { message = "Incorrect Username or Password"; } } else { message = exec.Message; } return(objUser); }