Пример #1
0
        /// <summary>
        /// 获取图片验证码
        /// </summary>
        /// <returns></returns>
        public ActionResult GetVerifyCode()
        {
            string verifyCode = WebCommonHelper.CreateVerifyCode(5);

            TempData["verifyCodeFront"] = verifyCode;
            MemoryStream ms = ImageFactory.GenerateImage(verifyCode, 51, 100, 20, 6);

            return(File(ms, "image/jpeg"));
        }
Пример #2
0
 public long UpdateUser(string phoneNum, string password, long?cityId)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         CommonService <UserEntity> userService = new CommonService <UserEntity>(ctx);
         UserEntity user = userService.GetAll().Include(u => u.CityEntity).SingleOrDefault(u => u.PhoneNum == phoneNum);
         if (user == null)
         {
             throw new Exception("用户不存在" + phoneNum);
         }
         user.PasswordSalt = WebCommonHelper.CreateVerifyCode(4);
         user.PasswordHash = Common.CommonHelper.CalcMD5(user.PasswordSalt + password);
         user.CityId       = cityId;
         ctx.SaveChanges();
         return(user.Id);
     }
 }
Пример #3
0
        public long AddNewUser(string phoneNum, string password, long?cityId)
        {
            UserEntity user = new UserEntity();

            user.PhoneNum     = phoneNum;
            user.PasswordSalt = WebCommonHelper.CreateVerifyCode(4);
            user.PasswordHash = Common.CommonHelper.CalcMD5(user.PasswordSalt + password);
            user.CityId       = cityId;
            using (ZSZDbContext ctx = new ZSZDbContext())
            {
                CommonService <UserEntity> userService = new CommonService <UserEntity>(ctx);
                bool exists = userService.GetAll().Any(u => u.PhoneNum == phoneNum);
                if (exists)
                {
                    throw new ArgumentException("手机号已存在" + phoneNum);
                }
                ctx.Users.Add(user);
                ctx.SaveChanges();
                return(user.Id);
            }
        }