public bool SendNewsletter(string subject, string body) { DALUsers dal = new DALUsers(connectionString); List <User> subscribedUsers = dal.GetByNewsletter(); MailMessage newsletter = new MailMessage(); newsletter.From = new MailAddress("*****@*****.**"); try { foreach (User subscribedUser in subscribedUsers) { newsletter.To.Clear(); newsletter.To.Add(new MailAddress(subscribedUser.Email.ToString())); // accept portuguese chars newsletter.BodyEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1"); newsletter.Subject = "Wizball - " + subject; newsletter.Body = "Dear " + subscribedUser.Username + "," + Environment.NewLine + Environment.NewLine; newsletter.Body += body + Environment.NewLine + Environment.NewLine + Environment.NewLine; newsletter.Body += "If you do not want to receive more emails like this, please unsubscribe to the newsletter service in the profile section of wizball website." + Environment.NewLine + Environment.NewLine; newsletter.Body += "We work hard every day so you can always have the results you want in your bets." + Environment.NewLine + Environment.NewLine; newsletter.Body += "Our best regards," + Environment.NewLine; newsletter.Body += "Wizball support team"; SendEmail(newsletter); } return(true); } catch (Exception ex) { return(false); } }
public User UserLogin(string Username, string Password) { DALUsers dalUsers = new DALUsers(connectionString); User user = dalUsers.Login(Username, Password); EntityBuilder(user); return(user); }
// USER METHODS. public List <User> GetAllUsers() { DALUsers dal = new DALUsers(connectionString); List <User> lstUsers = dal.GetAll(); lstUsers.ForEach(EntityBuilder); return(lstUsers); }
/// <summary> /// 编辑用户 /// </summary> /// <param name="Rid"></param> /// <returns></returns> public ActionResult Edit(int Rid) { var model = new Users(); if (Rid > 0) { model = new DALUsers().GetSingleUsers(Rid); } return(View(model)); }
public List <User> GetUsersByState(string UserStateId) { if (string.IsNullOrEmpty(UserStateId)) { return(null); } DALUsers dalUsers = new DALUsers(connectionString); return(dalUsers.GetByState(UserStateId)); }
/// <summary> /// 删除用户 /// </summary> /// <param name="Rid"></param> /// <returns></returns> public ActionResult Delete(int Rid) { ResultMsg msg = new ResultMsg(); if (Rid > 0) { msg = new DALUsers().Delete(Rid); } return(Json(new { Success = msg.Success, Result = msg.ReturnInt, ErrMsg = msg.ErrMsg })); }
/// <summary> /// 分页查询 /// </summary> /// <param name="model"></param> /// <param name="currentPage"></param> /// <param name="pageSize"></param> /// <returns></returns> public ActionResult PageList(Users model, int currentPage = 1, int pageSize = 20) { int recordCount = 0; List <Users> users = new DALUsers().QueryPagination(currentPage, pageSize, out recordCount, model).ToList(); ViewBag.RecordCount = recordCount; ViewBag.CurrentPage = currentPage; ViewBag.PageSize = pageSize; ViewBag.PageCount = Math.Ceiling((double)recordCount / (double)pageSize); ViewBag.Model = model; return(View(users)); }
public bool UsernameExists(string Username) { DALUsers dalUsers = new DALUsers(connectionString); User user = dalUsers.GetByUsername(Username); if (user is null) { return(false); } else { return(true); } }
public bool UserMailExists(string Email) { DALUsers dalUsers = new DALUsers(connectionString); User user = dalUsers.GetByEmail(Email); if (user is null) { return(false); } else { return(true); } }
public bool UpdateUser(User User) { if (User is null) { return(false); } if (!IsValidEmail(User.Email)) { return(false); } DALUsers dalUsers = new DALUsers(connectionString); return(dalUsers.Update(User)); }
public User GetUserById(string Id) { if (string.IsNullOrEmpty(Id)) { return(null); } DALUsers dal = new DALUsers(connectionString); User user = dal.GetById(Id); EntityBuilder(user); return(user); }
/// <summary> /// 添加/修改保存 /// </summary> /// <param name="model"></param> /// <returns></returns> public ActionResult Save(Users model) { model.Crdate = DateTime.Now; ResultMsg msg = new ResultMsg(); //修改 if (model.Rid > 0) { msg = new DALUsers().Update(model); } //添加 else if (model.Rid == 0) { msg = new DALUsers().Insert(model); } return(Json(new { Success = msg.Success, Result = msg.ReturnInt, ErrMsg = msg.ErrMsg })); }
public bool InsertUser(User User) { // User Validations. if (User is null) { return(false); } if (!IsValidEmail(User.Email)) { return(false); } // Insert User and get his Id. DALUsers dalUsers = new DALUsers(connectionString); int userId = dalUsers.Insert(User); // Creates and inserts default user_history for the current user. UserHistory userHistory = new UserHistory() { Admin = new Admin() { Id = 1 }, User = new User() { Id = userId }, Description = "User registration.", BeforeState = new UserState() { Id = 1 }, AfterState = new UserState() { Id = 1 } }; InsertUserHistory(userHistory); return(true); }
public ActionResult InternalUserEdit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ApplicationUser user = db.Users.Find(id); if (user == null) { return(HttpNotFound()); } var userDTO = Mapper.Map <ApplicationUser, UserDTO>(user); userDTO.InternalRoleEnum = DALUsers.GetInternalUserRoleEnum(userDTO.Id); ViewBag.UserId = User.Identity.GetUserId(); return(View(userDTO)); }
public ActionResult EndUserEdit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ApplicationUser user = db.Users.Find(id); if (user == null) { return(HttpNotFound()); } var userDTO = Mapper.Map <ApplicationUser, UserDTO>(user); userDTO.EndClientEnum = DALUsers.GetEndUserRoleEnum(userDTO.Id); userDTO.TrainingStartDateString = Global.DateTimeToPostableString(user.TrainingStartDate); ViewBag.UserId = User.Identity.GetUserId(); return(View(userDTO)); }
/// <summary> /// 用户登录 /// </summary> /// <param name="UserName"></param> /// <param name="Password"></param> /// <returns></returns> public ActionResult Login(string UserName, string Password) { Users user = new DALUsers().CheckPassword(UserName, Password); if (user != null && user.Rid > 0) { var data = JsonConvert.SerializeObject(user); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(0, user.LoginName, DateTime.Now, DateTime.Now.AddHours(72), true, data, FormsAuthentication.FormsCookiePath); //返回登录结果、用户信息、用户验证票据信息 var Ticket = FormsAuthentication.Encrypt(ticket); //将身份信息保存在cookie中 返回给客户端 var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, Ticket); cookie.HttpOnly = true; //是否为持久化cookie 会话性cookie保存于内存中。关闭浏览器则会话性cookie会过期消失;持久化cookie则不会,直至过期时间已到或确认注销。 if (ticket.IsPersistent) { //设置cookie到期时间 cookie.Expires = ticket.Expiration; } var context = System.Web.HttpContext.Current; if (context == null) { throw new InvalidOperationException(); } //把票据信息写入Cookie和Session //SetAuthCookie方法用于标识用户的Identity状态为true //若不设置cookia的过期时间,默认关闭浏览器(会话)清空cookia,若有设置则按照设置的过期时间 context.Response.Cookies.Remove(cookie.Name); context.Response.Cookies.Add(cookie); return(Json(new { Success = true, Result = user, ErrMsg = "", Token = Ticket })); } else { return(Json(new { Success = false, Result = "", ErrMsg = "账号名或密码错误", Token = "" })); } }
public bool RecoverUserPassword(string Email) { if (!IsValidEmail(Email)) { return(false); } DALUsers dalUsers = new DALUsers(connectionString); User user = dalUsers.GetByEmail(Email); if (user is null) { return(false); } else { MailMessage email = new MailMessage(); email.From = new MailAddress("*****@*****.**"); email.To.Add(new MailAddress(user.Email.ToString())); email.Subject = "Wizball - Password Recover"; email.Body = "Dear " + user.Username + "," + Environment.NewLine + Environment.NewLine; email.Body += "You recently filed a password recovery request." + Environment.NewLine + Environment.NewLine; email.Body += "As requested, we send your account information and strongly recommend you to change your password." + Environment.NewLine + Environment.NewLine + Environment.NewLine; email.Body += "Account information:" + Environment.NewLine; email.Body += " - Username: "******" - Password: "******" - Email: " + user.Email + Environment.NewLine + Environment.NewLine + Environment.NewLine; email.Body += "If you did not requested this information, we highly recommend you to change your password." + Environment.NewLine; email.Body += "You can also contact us to solve the problem." + Environment.NewLine + Environment.NewLine; email.Body += "We work hard every day so you can always have the results you want in your bets." + Environment.NewLine + Environment.NewLine; email.Body += "Our best regards," + Environment.NewLine; email.Body += "Wizball support team"; SendEmail(email); return(true); } }