//POST : /api/ApplicationUser/Register public async Task <Object> PostApplicationUser(UserModel model) { var used = _context.HTUsers.ToList().Where(x => x.Username == model.Username); if (used.Count() > 0) { return(false); } var password = PasswordHash.EncodePassword(model.Password); var applicationUser = new HTUser() { Username = model.Username, PasswordHash = password, Email = model.Email, HoTen = model.HoTen }; try { await _context.HTUsers.AddAsync(applicationUser); await _context.SaveChangesAsync(); return(used); } catch (Exception ex) { throw ex; } }
public JsonResult CheckIdentity(string Phone, string Code) { ResultMessage result = new ResultMessage(); if (!_phoneValidService.ValidPhone(Phone, Code)) { result.Code = -1; result.Message = "验证码错误"; } else { var user = _userService.GetUserByPhone(Phone); if (user != null) { #region 更新购物车 if (!string.IsNullOrEmpty(assets.CookieTag)) { _shopcartService.BindCart(assets.CookieTag, user.Id); } //管理员id CookieHelper.SetCookie("_memid", Encrypt.Encode(user.Id.ToString(), "SmartShop")); CookieHelper.SetCookie("_memname", Encrypt.Encode(user.NickName.ToString(), "SmartShop")); CookieHelper.SetCookie("_memphone", Encrypt.Encode(user.Mobile.ToString(), "SmartShop")); #endregion result.Code = 1; result.Message = "登录成功"; } else { HTUser newuser = new HTUser(); newuser.Mobile = Phone; newuser.Id = _userService.InsertUser(newuser); if (newuser.Id > 0) { #region 更新购物车 if (!string.IsNullOrEmpty(assets.CookieTag)) { _shopcartService.BindCart(assets.CookieTag, user.Id); } //管理员id CookieHelper.SetCookie("_memid", Encrypt.Encode(user.Id.ToString(), "SmartShop")); CookieHelper.SetCookie("_memname", Encrypt.Encode(user.NickName.ToString(), "SmartShop")); CookieHelper.SetCookie("_memphone", Encrypt.Encode(user.Mobile.ToString(), "SmartShop")); #endregion result.Code = 1; result.Message = "登录成功"; } } } return(Json(result, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 插入用户数据 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int InsertUser(HTUser entity) { return(_userRepository.InsertAndGetId(entity)); }