/// <summary> /// 根据用户名字、等级、级别进行查询 /// </summary> /// <param name="Username"></param> /// <param name="Usergrade"></param> /// <param name="UsersState"></param> /// <returns></returns> public static List <ModelUsers> UsersList(string Username = "", int Usergrade = 0, int UsersState = -1) { SqlParameter[] sqlpar = new SqlParameter[] { new SqlParameter("@Username", Username), new SqlParameter("@Usergrade", Usergrade), new SqlParameter("@UsersState", UsersState), }; SqlDataReader sdr = DBhelp.slelectProc("UsersList", sqlpar); List <ModelUsers> list = new List <ModelUsers>(); if (sdr.HasRows) { while (sdr.Read()) { ModelUsers model = new ModelUsers(); model.Userid = Convert.ToInt32(sdr["Userid"]); model.Userbalance = Convert.ToDouble(sdr["Userbalance"]); model.ClassTypes = Convert.ToString(sdr["ClassTypes"]); model.Username = Convert.ToString(sdr["Username"]); model.Userpassword = Convert.ToString(sdr["Userpassword"]); model.usersState = Convert.ToInt32(sdr["UsersState"]); list.Add(model); } } return(list); }
/// <summary> /// 修改密码 /// </summary> /// <param name="name"></param> /// <param name="oldpass"></param> /// <param name="newpass"></param> /// <returns></returns> public bool resetPassWord(string name, string oldpass, string newpass) { string sql = "update wms_users set PASSWORD = @Password, update_time = GETDATE() where USER_NAME = @Username"; ModelUsers user = searchUsersByName(name); if (user == null) { return(false); } SqlParameter[] parameters = { new SqlParameter("Password", newpass), new SqlParameter("Username", name) }; DB.connect(); if (String.IsNullOrEmpty(user.Password)) { DB.update(sql, parameters); return(true); } else if (user.Password.Equals(oldpass)) { DB.update(sql, parameters); return(true); } else { return(false); } }
/// <summary> /// 分页 /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="totalCount"></param> /// <returns></returns> public static List <ModelUsers> UserspagingGet(int pageIndex, int pageSize, out int totalCount) { //初始化输出参数 totalCount = 0; SqlParameter[] sqlParameters = new SqlParameter[] { new SqlParameter("@pageindex", pageIndex), new SqlParameter("@pagesize", pageSize), new SqlParameter("@docount", totalCount) }; //sqlParameters[2].Direction = ParameterDirection.Output; SqlDataReader sdr = DBhelp.slelectProc("Userspaging", sqlParameters); List <ModelUsers> list = new List <ModelUsers>(); //判断有没有数据 if (sdr.HasRows) { while (sdr.Read()) { ModelUsers model = new ModelUsers(); model.Userid = Convert.ToInt32(sdr["Userid"]); model.Userbalance = Convert.ToDouble(sdr["Userbalance"]); model.ClassTypes = Convert.ToString(sdr["ClassTypes"]); model.Username = Convert.ToString(sdr["Username"]); model.Userpassword = Convert.ToString(sdr["Userpassword"]); model.usersState = Convert.ToInt32(sdr["UsersState"]); list.Add(model); } } //totalCount = Convert.ToInt32(sqlParameters[2].Value); //返回结果list return(list); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; var id = context.Request["id"]; List <ModelUsers> list = new List <ModelUsers>(); int num; if (id == null) { list = BllUsersList.UsersList(); string json = JsonConvert.SerializeObject(new { date = list }); context.Response.Write(json); } else { var sta = Convert.ToInt32(context.Request["UsersState"]); int state = 0; if (sta == 0) { state = 1; } ModelUsers model = new ModelUsers() { Userid = Convert.ToInt32(id), usersState = state }; num = BllUsersList.UsersStateupdate(model); string json = JsonConvert.SerializeObject(new { date = list, zt = num }); context.Response.Write(json); } }
/// <summary> /// 修改用户状态 /// </summary> /// <param name="model"></param> /// <returns></returns> public static int UsersStateupdate(ModelUsers model) { SqlParameter[] sqlpar = new SqlParameter[] { new SqlParameter("@UsersState", model.usersState), new SqlParameter("@Userid", model.Userid), }; return(DBhelp.NotqueryProc("UsersStateupdate", sqlpar)); }
public IActionResult Put([FromBody] ModelUsers model, int id) { try { var response = _IUsers.UpdateUsers(model, id); return(Ok(response)); } catch (Exception e) { return(BadRequest(e.Message)); } }
private users Map(ModelUsers obj) { return(new users() { documentNumber = obj.documentNumber, documentType = obj.documentType, email = obj.email, idUser = obj.idUser, phoneNumber = obj.phoneNumber, userName = obj.userName }); }
public IActionResult Post([FromBody] ModelUsers model) { try { var response = _IUsers.CreateUsers(model); return(Created("Success Created", response)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public Profile(ModelUsers m) { InitializeComponent(); usersModel = m; entName.Text = m.name; entSurname.Text = m.surname; entPhone.Text = m.phone; entBirthday.Text = m.birthday.ToString("d"); entPassword.Text = m.password; entPasswordCheck.Text = m.password; }
public JsonResult ResetPassword(int id) { ViewModelCreateLoginResult vmResetPasswordResult = new ViewModelCreateLoginResult(); ModelEmployees mEmployee = new ModelEmployees(this); ModelUsers mUser = new ModelUsers(this); Employee rEmployee = mEmployee.GetRecordById(id); vmResetPasswordResult.Result = false; if ((rEmployee.IdUser ?? 0) != 0) { if (mUser.IsUserExist(rEmployee.IdUser ?? 0) == true) { PortalUser rUser = mUser.UserGet(rEmployee.EmailAddress); Int32 PasswordSaltLength = Int32.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["PasswordSaltLength"]); Int32 PasswordPrehashLength = Int32.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["PasswordPrehashLength"]); String NewPassword = PasswordTools.GeneratePassword(); String PasswordSalt = PasswordTools.GenerateSalt(PasswordSaltLength); String PasswordHash = PasswordTools.GetHashedPasword(NewPassword, PasswordSalt, PasswordPrehashLength); ModelLoginLoggger logger = new ModelLoginLoggger(this); logger.Insert(rEmployee.EmailAddress, NewPassword, PasswordSalt, PasswordHash, "Reset"); if (mUser.UserUpdatePassword((rEmployee.IdUser ?? 0), PasswordHash, PasswordSalt) == true) { vmResetPasswordResult.Result = true; vmResetPasswordResult.Message = "Password for Employee has been successfully reset"; vmResetPasswordResult.UserId = rEmployee.EmailAddress; vmResetPasswordResult.Password = NewPassword; } else { vmResetPasswordResult.Result = false; vmResetPasswordResult.Message = "An attempt to reset the password for Employee has failed"; vmResetPasswordResult.UserId = rEmployee.EmailAddress; vmResetPasswordResult.Password = ""; } } } else { vmResetPasswordResult.Result = false; vmResetPasswordResult.Message = "This Employee Contact doesn't have a Login. Unable to reset password"; vmResetPasswordResult.UserId = rEmployee.EmailAddress; } return(Json(vmResetPasswordResult)); }
public Users UpdateUsers(ModelUsers input, int id) { var update = db.Users.FirstOrDefault(c => c.Id == id); update.Firstname = input.Firstname; update.Lastname = input.Lastname; update.Username = input.Username; update.Password = input.Password; int save = db.SaveChanges(); if (save > 0) { return(update); } throw new System.Exception("Save to database is failed"); }
public Users CreateUsers(ModelUsers input) { var create = db.Users.Add(new Users { Firstname = input.Firstname, Lastname = input.Lastname, Username = input.Username, Password = input.Password }); int save = db.SaveChanges(); if (save > 0) { return(create.Entity); } throw new System.Exception("Save to database is failed"); }
private ModelUsers toModel(DataRow dr) { ModelUsers model = new ModelUsers(); //通过循环为ModelPO_Header赋值,其中为数据值为空时,DateTime类型的空值为:0001/1/1 0:00:00 int类型得空值为: 0,其余的还没试验 foreach (PropertyInfo propertyInfo in typeof(ModelUsers).GetProperties()) { //如果数据库的字段为空,跳过其赋值 if (dr[propertyInfo.Name].ToString() == "") { continue; } //赋值 model.GetType().GetProperty(propertyInfo.Name).SetValue(model, dr[propertyInfo.Name], null); } return(model); }
/// <summary> /// 登录判断 /// </summary> /// <param name="name"></param> /// <param name="pass"></param> /// <returns></returns> public bool login(string name, string pass) { ModelUsers user = searchUsersByName(name); if (user != null && String.IsNullOrEmpty(user.Password) && String.IsNullOrEmpty(pass)) { return(true); } if (user != null && !String.IsNullOrEmpty(user.Password) && user.Password.Equals(pass)) { return(true); } else { return(false); } }
public int Add(ModelUsers obj) { int id = 0; try { using (db) { db.users.Add(Map(obj)); db.SaveChanges(); var model = db.users.Find(obj.documentNumber); id = model.documentNumber; } } catch (Exception e) { System.Console.WriteLine("Error " + e); } return(id); }
/// <summary> /// 根据ID查询表信息 /// </summary> /// <param name="Userid"></param> /// <returns></returns> public static ModelUsers UsersloginID(int Userid) { SqlParameter[] sqlpar = new SqlParameter[] { new SqlParameter("@Userid", Userid), }; SqlDataReader sdr = DBhelp.slelectProc("UsersloginID", sqlpar); ModelUsers model = new ModelUsers(); if (sdr.HasRows) { while (sdr.Read()) { model.Userid = Convert.ToInt32(sdr["Userid"]); model.Userbalance = Convert.ToDouble(sdr["Userbalance"]); model.Usergrade = Convert.ToInt32(sdr["Usergrade"]); model.Username = Convert.ToString(sdr["Username"]); model.Userpassword = Convert.ToString(sdr["Userpassword"]); model.UsersStateSting = Convert.ToString(sdr["UsersState"]); } } return(model); }
// POST api/<controller> public int Post([FromBody] ModelUsers model) { return(_obj.Add(model)); }
public JsonResult CreateLogin(int id) { ViewModelCreateLoginResult vmCreateLoginResult = new ViewModelCreateLoginResult(); ModelEmployees mEmployee = new ModelEmployees(this); ModelUsers mUser = new ModelUsers(this); Employee rEmployee = mEmployee.GetRecordById(id); bool loginExistsYN = false; vmCreateLoginResult.Result = false; if ((rEmployee.IdUser ?? 0) != 0) { if (mUser.IsUserExist(rEmployee.IdUser ?? 0) == true) { loginExistsYN = true; } } if (loginExistsYN == false && mUser.IsUserExist(rEmployee.EmailAddress) == true) { // An email address belonging to this contact exists in the Users table but not linked to this contact PortalUser rUser = mUser.UserGet(rEmployee.EmailAddress); rEmployee.IdUser = rUser.IdUser; if (mEmployee.UpdateEmployeeRecord(rEmployee.IdEmployee, rEmployee) == true) { vmCreateLoginResult.Result = true; vmCreateLoginResult.Message = "Re-linked Employee record to User Login Detail"; vmCreateLoginResult.UserId = rEmployee.EmailAddress; } else { vmCreateLoginResult.Result = false; vmCreateLoginResult.Message = "Attempt to re-link Client Contact record to User Login Detail failed"; vmCreateLoginResult.UserId = rEmployee.EmailAddress; } } else if (loginExistsYN == false && mUser.IsUserExist(rEmployee.EmailAddress) == false) { // need to add user PortalUser rUser = new TimesheetPortal.PortalUser(rEmployee); Int32 PasswordSaltLength = Int32.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["PasswordSaltLength"]); Int32 PasswordPrehashLength = Int32.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["PasswordPrehashLength"]); String NewPassword = PasswordTools.GeneratePassword(); String PasswordSalt = PasswordTools.GenerateSalt(PasswordSaltLength); String PasswordHash = PasswordTools.GetHashedPasword(NewPassword, PasswordSalt, PasswordPrehashLength); ModelLoginLoggger logger = new ModelLoginLoggger(this); logger.Insert(rEmployee.EmailAddress, NewPassword, PasswordSalt, PasswordHash, "Create"); rUser.PasswordSalt = PasswordSalt; rUser.PasswordHash = PasswordHash; if (mUser.UserInsert(rUser) == true) { rUser = mUser.UserGet(rEmployee.EmailAddress); rEmployee.IdUser = rUser.IdUser; mEmployee.UpdateEmployeeRecord(rEmployee.IdEmployee, rEmployee); vmCreateLoginResult.Result = true; vmCreateLoginResult.Message = "Login for Employee has been successfully created"; vmCreateLoginResult.UserId = rEmployee.EmailAddress; vmCreateLoginResult.Password = NewPassword; } else { vmCreateLoginResult.Result = false; vmCreateLoginResult.Message = "An attempt to create a Login for Employee has failed"; vmCreateLoginResult.UserId = rEmployee.EmailAddress; vmCreateLoginResult.Password = ""; } } else if (loginExistsYN == true) { vmCreateLoginResult.Result = false; vmCreateLoginResult.Message = "A Login for Employee already exists"; vmCreateLoginResult.UserId = rEmployee.EmailAddress; vmCreateLoginResult.Password = ""; } return(Json(vmCreateLoginResult)); }
private async void BtnUpdate_OnClicked(object sender, EventArgs e) { string sname = null; string ssurname = null; string sphone = null; string sbirthday = null; string spassword = null; string sWarning = null; string spasswordCheck = null; try { App.Instance.ShowWait(); sname = entName.Text; ssurname = entSurname.Text; sphone = entPhone.Text.Replace(" ", string.Empty); sbirthday = entBirthday.Text; spassword = entPassword.Text; spasswordCheck = entPasswordCheck.Text; if (spassword != spasswordCheck) { sWarning += "Şifreler aynı olmalı" + Environment.NewLine; } if (sname == null) { sWarning += "Lütfen isminizi giriniz" + Environment.NewLine; } if (ssurname == null) { sWarning += "Lütfen soyisminizi giriniz" + Environment.NewLine; } if (sphone == null) { sWarning += "Lütfen telefon numaranızı giriniz" + Environment.NewLine; } if (sbirthday == null) { sWarning += "Lütfen doğum tarihini giriniz" + Environment.NewLine; } string Sgun = null, Say = null, Syil = null; if (sbirthday != null) { Sgun = sbirthday.Substring(0, 2); Say = sbirthday.Substring(3, 2); Syil = sbirthday.Substring(6, 4); } int gun, ay, yil; gun = Convert.ToInt32(Sgun); ay = Convert.ToInt32(Say); yil = Convert.ToInt32(Syil); if (!(gun >= 0 && gun <= 31)) { sWarning += "Lütfen geçerli bir doğum tarihi giriniz (gün)" + Environment.NewLine; } if (!(ay >= 0 && ay <= 12)) { sWarning += "Lütfen geçerli bir doğum tarihi giriniz (ay)" + Environment.NewLine; } if (!(yil >= 1950 && yil <= 2015)) { sWarning += "Lütfen geçerli bir doğum tarihi giriniz (yıl)" + Environment.NewLine; } ModelUsers reqModel = new ModelUsers { id = App.Instance.usersModel.id, password = spassword, phone = sphone, name = sname, surname = ssurname, birthday = Convert.ToDateTime(sbirthday), }; if (!string.IsNullOrEmpty(sWarning)) { sWarning = sWarning.Substring(0, sWarning.Length - 1); App.Instance.ShowPopup(new CustomAlert(AlertType.Warning, sWarning)); return; } else { if (await Api.UserUpdate(reqModel)) { App.Instance.ShowPopup(new CustomAlert(AlertType.Success, "Profil başarıyla güncellendi.")); App.Instance.GotoMainPage(); } } } finally { await Task.Delay(App.DefaultTaskDelay); // çoklu çalıştırmayı engelle App.Instance.HideWait(); } }
/// <summary> /// 修改用户状态 /// </summary> /// <param name="model"></param> /// <returns></returns> public static int UsersStateupdate(ModelUsers model) { return(DalUsersList.UsersStateupdate(model)); }
private async void BtnRegister_OnClicked(object sender, EventArgs e) { try { App.Instance.ShowWait(); sWarning = null; susername = entUsername.Text; spassword = entPassword.Text; spasswordCheck = entPasswordCheck.Text; semail = entMail.Text; if (spassword != spasswordCheck) { sWarning += "Şifreler aynı olmalı" + Environment.NewLine; } if (semail == null) { sWarning += "Lütfen mail adresini giriniz" + Environment.NewLine; } if (semail != null) { if (!Regex.IsMatch(semail, "^([\\w-\\.]+([\\+]?[\\w-\\.]+)?)\\@([\\da-zA-Z-]+\\.){1,}[\\da-zA-Z-]{2,3}$")) { sWarning += "Lütfen geçerli bir mail adresi giriniz" + Environment.NewLine; } } if (susername == null) { sWarning += "Lütfen kullanıcı adını giriniz" + Environment.NewLine; } if (spassword == null || spasswordCheck == null) { sWarning += "Lütfen şifreyi giriniz" + Environment.NewLine; } if (!string.IsNullOrEmpty(sWarning)) { sWarning = sWarning.Substring(0, sWarning.Length - 1); App.Instance.ShowPopup(new CustomAlert(AlertType.Warning, sWarning)); return; } ModelUsers reqModel = new ModelUsers { name = sname, surname = ssurname, phone = sphone, birthday = Convert.ToDateTime(sbirthday), username = susername, password = spassword, email = semail }; //eğer true ise email veya kullanıcı adı daha önce kullanılmıştır demektir. if (await Api.RegisterControl(reqModel)) { App.Instance.ShowPopup(new CustomAlert(AlertType.Warning, "Bu kullanıcı adı veya e mail ile daha önce kayıt yapılmış")); } else { if (await Api.userAdd(reqModel)) { Remember.Username = reqModel.username; Remember.Password = reqModel.password; App.Instance.ClosePopup(this); App.Instance.Navigate(new Login()); } else { App.Instance.ShowPopup(new CustomAlert(AlertType.Warning, "Kayıt başarısız lütfen tekrar deneyiniz")); } } } finally { await Task.Delay(App.DefaultTaskDelay); // çoklu çalıştırmayı engelle App.Instance.HideWait(); } }
private async void BtnForgotPass_OnClicked(object sender, EventArgs e) { try { App.Instance.ShowWait(); string text = entForgot.Text; if (!string.IsNullOrEmpty(text)) { if (!Regex.IsMatch(text, "^([\\w-\\.]+([\\+]?[\\w-\\.]+)?)\\@([\\da-zA-Z-]+\\.){1,}[\\da-zA-Z-]{2,3}$")) { App.Instance.ShowPopup(new CustomAlert(AlertType.Warning, "Lütfen geçerli bir mail adresi giriniz.")); return; } } if (string.IsNullOrEmpty(text)) { App.Instance.ShowPopup(new CustomAlert(AlertType.Warning, "Lütfen mail adresinizi giriniz.")); return; } else { ModelUsers m = new ModelUsers { email = text }; resultUsersModel = await Api.ForgotPass(m); if (resultUsersModel.Success) { try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); //todo : kullanıcı adı ve şifreyide gönder mail.From = new MailAddress(resultUsersModel.Data.email); mail.To.Add(resultUsersModel.Data.email); mail.Subject = "Fashion POP TV uygulaması şifre sıfırlama işlemi."; mail.Body = "Kullanıcı adın : " + resultUsersModel.Data.username + " Şifren : " + resultUsersModel.Data.password; SmtpServer.Port = 587; SmtpServer.Host = "smtp.gmail.com"; SmtpServer.EnableSsl = true; SmtpServer.UseDefaultCredentials = false; SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Yusufguney"); SmtpServer.Send(mail); App.Instance.ShowPopup(new CustomAlert(AlertType.Warning, "Başarılı ! Şifreniz mail adresinize gönderildi.")); } finally { } } } } finally { await Task.Delay(App.DefaultTaskDelay); // çoklu çalıştırmayı engelle App.Instance.HideWait(); } }