public ActionResult EditUser(User user) { try { UserService service = new UserService(); var oldUser = service.GetUserById(UserInfo.UserId); if (oldUser != null) { oldUser.Adress = user.Adress; oldUser.QQ = user.QQ; oldUser.LocationId = Request.Form["LocationId[]"]; if (!string.IsNullOrEmpty(Request.Form["Photo"])) { oldUser.Photo = Request.Form["Photo"]; } if (service.UserUpdate(oldUser)) { Session[USERINFO] = oldUser; } } } catch (Exception ex) { LogService.Log("会员列表", ex.ToString()); } return RedirectToAction("ViewUser"); }
public TradeController() { tradeService = new TradeService(); orderService = new OrderService(); configService = new PublicConfigService(); userService = new UserService(); }
/// <summary> /// 上传证件 /// </summary> /// <returns></returns> public ActionResult Identify() { RequireLogin(); UserViewModel model = new UserViewModel { UserEntity = UserInfo }; try { UserService service = new UserService(); model.VipInfo = service.GetUserVipInfoByUserId(UserInfo.UserId); } catch (Exception e) { LogService.Log("Identify 出错了!", e.ToString()); } model.ErrorMsg = GetErrorMessage(model.VipInfo); return View(model); }
public JsonResult CancelUserVip(int id) { AjaxResult result = new AjaxResult(); try { UserService service = new UserService(); if (!service.CancelUserVip(id)) { result.ExceptionInfo = "取消用户VIP失败"; } } catch (Exception ex) { LogService.Log("CancelUserVip", ex.ToString()); result.ExceptionInfo = "取消用户VIP失败"; } return Json(result); }
public JsonResult DeleteUser(int id) { AjaxResult result = new AjaxResult(); try { UserService service = new UserService(); if (!service.DeleteUser(id)) { result.ExceptionInfo = "删除失败"; } } catch (Exception ex) { LogService.Log("DeleteUser", ex.ToString()); result.ExceptionInfo = "删除失败"; } return Json(result); }
public ActionResult Login(LoginViewModel model) { var errorMsg = string.Empty; try { User result = null; if (ModelState.IsValid) { if (string.Equals(model.code, Session["validataCode"].ToString(), StringComparison.InvariantCultureIgnoreCase)) { userService = new UserService(); result = userService.Login(model.username, model.password); if (result != null) { Session[USERINFO] = result; return RedirectToAction("Index", "User", new { Area = "M" }); } else { errorMsg = "用户名或密码错误!"; } } else { errorMsg = "验证码输入错误!"; } } else { errorMsg = "信息填写有误!"; } } catch (Exception ex) { LogService.Log("注册用户", ex.ToString()); } model.ErrorMsg = errorMsg; return View(model); }
/// <summary> /// 上传证件 /// </summary> /// <returns></returns> public ActionResult Identify(string returnUrl = null) { if (!CurrentWeChatUser.IsUserLoggedIn) { return Redirect("/wechat/account/login"); } WeChatUserViewModel model = new WeChatUserViewModel { UserEntity = UserInfo }; try { UserService service = new UserService(); model.VipInfo = service.GetUserVipInfoByUserId(UserInfo.UserId); } catch (Exception e) { LogService.Log("Identify 出错了!", e.ToString()); } model.ErrorMsg = GetErrorMessage(model.VipInfo); ViewData["returnUrl"] = returnUrl; return View(model); }
public JsonResult CancelIdentify(int id) { AjaxResult result = new AjaxResult(); try { UserService service = new UserService(); User user = service.GetUserById(id); if (user.Vip.HasValue && user.Vip == (int)VipState.VIP) { result.ExceptionInfo = "该用户是VIP会员,不能取消认证。如确实需要,请先取消VIP会员之后重新尝试"; } else if (!service.CancelIdentify(id)) { result.ExceptionInfo = "取消会员认证失败"; } } catch (Exception ex) { LogService.Log("CancelIdentify", ex.ToString()); result.ExceptionInfo = "取消会员认证失败"; } return Json(result); }
public WorkingThread() { subscriptionService = new DemandSubscriptionService(); userService = new UserService(); demandService = new DemandService(); }
public ActionResult VipUserReview(int page = 1, int size = 10) { MemberViewModel viewModel = new MemberViewModel(); try { UserService service = new UserService(); int totalCount; viewModel.VipInfos = service.GetVipUserReviewList(page, size, out totalCount); viewModel.PageSize = size; viewModel.CurrentPage = page; viewModel.TotalCount = totalCount; } catch (Exception ex) { LogService.Log("VIP会员审核列表", ex.ToString()); } return View(viewModel); }
/// <summary> /// 会员统计 /// </summary> /// <param name="page"></param> /// <param name="size"></param> /// <param name="querytype"></param> /// <returns></returns> public ActionResult TongJi(string city = "-1", int resurce = -1, int querytype = -1, int page = 1, string Keyword="") { MemberViewModel viewModel = new MemberViewModel(); try { UserService service = new UserService(); int totalCount; viewModel.UserList = service.QuersyUsersByCityAndResource(city, resurce, page, 20, querytype, Keyword, out totalCount); viewModel.PageSize = 20; viewModel.PageStep = 5; viewModel.CurrentPage = page; viewModel.TotalCount = totalCount; viewModel.Resurce = resurce; viewModel.City = city; viewModel.QueryType = querytype; viewModel.Keyword = Keyword; } catch (Exception ex) { LogService.Log("会员列表", ex.ToString()); } return View(viewModel); }
/// <summary> /// 处理微信授权结果,更新用户信息 /// </summary> /// <param name="filterContext"></param> private bool HandleWechatAuthResult(string code) { bool isSuccessful = true; try { OAuthAccessTokenResult accessTokenResult = null; //通过,用code换取access_token accessTokenResult = OAuthApi.GetAccessToken(WeChatClient.App.AppId, WeChatClient.App.AppSecret, code); //LogService.LogWexin("AccessToken请求状态", accessTokenResult.errcode.ToString()); if (accessTokenResult.errcode == ReturnCode.请求成功) { //更新用户Open id Cookie var openIdCookie = new HttpCookie(WeChatOpenIdCookieName, accessTokenResult.openid); openIdCookie.Expires = DateTime.Now.AddMonths(1); Response.Cookies.Add(openIdCookie); //因为第一步选择的是OAuthScope.snsapi_userinfo,这里可以进一步获取用户详细信息 UserService userService = new UserService(); OAuthUserInfo userInfo = OAuthApi.GetUserInfo(accessTokenResult.access_token, accessTokenResult.openid); WeChatUser wechatUser = userService.GetWeChatUser(accessTokenResult.openid); // 用户第一次访问,添加用户信息 if (wechatUser == null) { userService.WeChatUserSubscribe(accessTokenResult.openid, false, true); wechatUser = userService.GetWeChatUser(accessTokenResult.openid); } else { wechatUser.HasAuthorized = true; } // 更新用户详细信息 if (wechatUser != null) { // Updates wechat user info wechatUser.AccessToken = accessTokenResult.access_token; wechatUser.AccessTokenExpired = false; wechatUser.AccessTokenExpireTime = DateTime.Now.AddSeconds(accessTokenResult.expires_in); wechatUser.City = userInfo.city; wechatUser.County = userInfo.country; wechatUser.NickName = userInfo.nickname; wechatUser.Photo = userInfo.headimgurl; wechatUser.Province = userInfo.province; wechatUser.Sex = userInfo.sex; if (userService.UpdateWeChatUser(wechatUser)) { //Updates current wechat user Session[WeChatUserInfo] = wechatUser; //LogService.LogWexin("保存微信用户资料成功", ""); } else { LogService.LogWexin("保存微信用户资料失败", wechatUser.OpenId); isSuccessful = false; } } } } catch (Exception ex) { LogService.LogWexin("QAuth获取用户信息发生异常", ex.ToString()); isSuccessful = false; } return isSuccessful; }
/// <summary> /// 更新默认城市地址 /// </summary> /// <param name="cityId"></param> /// <returns></returns> public virtual bool UpdateDefaultCity(string cityId) { bool isSuccessful = false; if (CurrentUser.IsNotNull()) { try { var city = ConvertToCityObject(cityId); if (city.IsNotNull()) { UserService userService = new UserService(); CurrentUser.LocationId = city.ParentId + "," + city.Id + ","; isSuccessful = userService.UserUpdate(CurrentUser); } } catch(Exception ex) { LogService.Log("UpdateDefaultCity", ex.ToString()); } } return isSuccessful; }
public ActionResult Identify(string identifyImgUrl, string returnUrl = null) { WeChatUserViewModel model = new WeChatUserViewModel { UserEntity = UserInfo }; if (!string.IsNullOrWhiteSpace(identifyImgUrl)) { UserService service = new UserService(); try { UserVip vipInfo = service.GetUserVipInfoByUserId(UserInfo.UserId); CurrentUser.IdentiyImg = identifyImgUrl; CurrentUser.Vip = (int)VipState.Normal; if (service.UserUpdate(CurrentUser) && service.UpdateUserVipInfo(vipInfo.Id, vipInfo.OrderId, identifyImgUrl, DateTime.Now, DateTime.Now, vipInfo.Duration, vipInfo.Amount, VipState.Normal)) { model.ErrorMsg = "照片上传成功,等待管理员审核"; } // get it again model.VipInfo = service.GetUserVipInfoByUserId(UserInfo.UserId); if (string.IsNullOrEmpty(model.ErrorMsg)) { model.ErrorMsg = GetErrorMessage(model.VipInfo); } } catch (Exception e) { LogService.Log("Identify 出错了!", e.ToString()); model.ErrorMsg = "认证照片上传失败!"; } } else { model.ErrorMsg = "请选择认证照片!"; } if (!string.IsNullOrWhiteSpace(returnUrl)) { return Redirect(returnUrl); } return View(model); }
public ActionResult ToVip(FormCollection form) { try { UserService service = new UserService(); //service.SetUserToVip(UserInfo); } catch (Exception e) { LogService.Log("ToVip 出错了!", e.ToString()); } return View(); }
public AccountController() { userService = new UserService(); }
public ActionResult EditUser(int id) { MemberViewModel viewModel = new MemberViewModel(); try { UserService service = new UserService(); viewModel.SingleUser = service.GetUserById(id); } catch (Exception ex) { LogService.Log("会员列表", ex.ToString()); } return View(viewModel); }
public JsonResult VerifyUserName(string field, string value) { AjaxResult result = new AjaxResult(); try { userService = new UserService(); if (!userService.VerifyUserInfo(field, value)) { result.ExceptionInfo = "该用户名已经被注册!"; result.ErrorCode = 103; } } catch (Exception ex) { LogService.Log("VerifyUserName", ex.ToString()); result.ExceptionInfo = "出错了!"; result.ErrorCode = 102; } return Json(result); }
public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage) { var responseMessage = base.CreateResponseMessage<ResponseMessageText>(); responseMessage.Content = "有空再来"; try { // 取消关注事件,下边做些逻辑 UserService userService = new UserService(); userService.UnSubscribeWeChatUser(requestMessage.FromUserName); } catch (Exception ex) { LogService.Log("用户取消关注失败, WeChatID = " + requestMessage.FromUserName, ex.ToString()); } return responseMessage; }
/// <summary> /// 订阅(关注)事件 /// </summary> /// <returns></returns> public override IResponseMessageBase OnEvent_SubscribeRequest(RequestMessageEvent_Subscribe requestMessage) { var strongResponseMessage = CreateResponseMessage<ResponseMessageNews>(); strongResponseMessage.Articles.Add(GetWelcomeInfo()); try { // 关注事件,下边边注册微信用户 UserService userService = new UserService(); bool result = userService.WeChatUserSubscribe(requestMessage.FromUserName); if (!result) { LogService.Log("微信关注注册用户失败", "WeChatID = " + requestMessage.FromUserName); } } catch (Exception ex) { LogService.Log("微信关注注册用户失败, WeChatID = " + requestMessage.FromUserName, ex.ToString()); } return strongResponseMessage; }
/// <summary> /// 设置默认微信用户session信息来绕过微信授权检测,仅用于电脑测试。 /// </summary> private void SetWeChatUserSessionForTestingUseOnly() { WeChatUser wechatUser = new UserService().GetWeChatUserByWeChatUserId(112820);// 112816 if (wechatUser.IsNotNull()) { CurrentWeChatUser = wechatUser; if (wechatUser.UserId.HasValue) { User user = new UserService().GetUserById(wechatUser.UserId.Value); if (user.IsNotNull()) { CurrentUser = user; wechatUser.IsUserLoggedIn = IsUserLogin; wechatUser.IsUserIdentified = IsIdentified; wechatUser.IsUserVip = IsVip; } } } }
public ActionResult Register(SHTS.Model.User user) { var userRegisterViewModel = new UserRegisterViewModel(); try { userRegisterViewModel.User = user; var errorMsg = string.Empty; bool result = false; bool vcodeVail = false; //取消手机验证码逻辑 //if (Session["vcode"] == null) //{ // errorMsg = "请先输入手机验证码!"; //} //else if (!string.Equals(Session["vcode"].ToString(), // Request.Form["code"], StringComparison.InvariantCultureIgnoreCase)) //{ // errorMsg = "手机验证码输入错误!"; //} //else { vcodeVail = true; } if (vcodeVail) { userService = new UserService(); user.LoginIdentiy = user.UserName; user.Photo = ConfigurationManager.AppSettings["DefaultPhoto"]; //result = userService.UserRegister(user); if (result) { return RedirectToAction("Login"); } else { errorMsg = "注册失败"; } } if (!result) { userRegisterViewModel.ErrorMsg = errorMsg; SinglePageService singlePageService = new SinglePageService(); userRegisterViewModel.RegNotice = singlePageService.GetSingPageById("94"); } } catch (Exception ex) { LogService.Log("注册用户", ex.ToString()); } return View(userRegisterViewModel); }
/// <summary> /// 会员须知 /// </summary> /// <returns></returns> public ActionResult ToVip() { UserViewModel model = new UserViewModel { UserEntity = UserInfo }; try { UserService service = new UserService(); UserVip vipInfo = service.GetUserVipInfoByUserId(UserInfo.UserId); if (vipInfo != null && vipInfo.State.HasValue && vipInfo.State.Value == (int)VipState.VIP) { return Redirect(GetUrl("/Wechat/user/VipInfo")); } SinglePageService singlePageService = new SinglePageService(); model.ToVipNotice = singlePageService.GetSingPageById("95"); } catch (Exception e) { LogService.Log("ToVip 出错了!", e.ToString()); } return View(model); }
public JsonResult ReviewedVipInfo(int vipId, int userId) { AjaxResult result = new AjaxResult(); try { UserService service = new UserService(); if (!service.ReviewedVipInfo(vipId, userId)) { result.ExceptionInfo = "审核失败"; } } catch (Exception ex) { LogService.Log("ReviewedVipInfo", ex.ToString()); result.ExceptionInfo = "审核失败"; } return Json(result); }
public ActionResult UpdatePassword(string oldpassword, string newpassword) { UserViewModel model = new UserViewModel { UserEntity = UserInfo }; string message = null; try { if (string.Equals(oldpassword.ToMD5(), model.UserEntity.EncryptedPassword, StringComparison.InvariantCultureIgnoreCase)) { UserService service = new UserService(); model.UserEntity.EncryptedPassword = newpassword.ToMD5(); service.ResetUserPassword(model.UserEntity); } else { message = "原密码输入错误!"; } } catch (Exception e) { LogService.Log("UpdatePassword 出错了!", e.ToString()); message = "密码更新失败!"; } model.ErrorMsg = message; return View(model); }
public JsonResult SetUserVip(int id) { AjaxResult result = new AjaxResult(); try { UserService service = new UserService(); User user = service.GetUserById(id); if (user.Vip.HasValue && user.Vip == (int)VipState.VIP) { result.ExceptionInfo = "该用户已经是VIP会员"; } else if (user.Vip.HasValue && (user.Vip == (int)VipState.Normal || user.Vip == (int)VipState.Invalid)) { result.ExceptionInfo = "只有认证会员才能设置VIP,请先通知会员进行认证,保证信息准确"; } else if (!service.SetUserToVip(id)) { result.ExceptionInfo = "用户升级1年VIP失败"; } } catch (Exception ex) { LogService.Log("SetUserVip", ex.ToString()); result.ExceptionInfo = "用户升级1年VIP失败"; } return Json(result); }
public ActionResult EditUser(string UserId, string Cellphone, string Email, string QQ, string Address, string UCard, string SiteUrl) { MemberViewModel viewModel = new MemberViewModel(); try { UserService service = new UserService(); User user = service.GetUserById(int.Parse(UserId)); if (user != null) { user.Cellphone = Cellphone; user.Email = Email; user.QQ = QQ; user.Adress = Address; user.UCard = UCard; user.SiteUrl = SiteUrl; } service.UserUpdate(user); viewModel.SingleUser = service.GetUserById(user.UserId); ; } catch (Exception ex) { LogService.Log("会员列表", ex.ToString()); } return View(viewModel); }
/// <summary> /// Clears the current logged on user information. /// </summary> public void RefreshUser() { var userService = new Witbird.SHTS.BLL.Services.UserService(); Session[USERINFO] = userService.GetUserById(UserInfo.UserId); }
/// <summary> /// 微信授权验证返回 /// </summary> /// <param name="code">微信验证code</param> /// <param name="state">用户原始访问地址</param> /// <returns></returns> public ActionResult CallBack(string code, string state) { ActionResult result = null; bool isSuccessFul = false; var callBackUrl = state; try { if (string.IsNullOrEmpty(code)) { result = Content("您拒绝了授权"); } else { OAuthAccessTokenResult accessTokenResult = null; //通过,用code换取access_token accessTokenResult = OAuthApi.GetAccessToken(WeChatClient.App.AppId, WeChatClient.App.AppSecret, code); //LogService.LogWexin("AccessToken请求状态", accessTokenResult.errcode.ToString()); if (accessTokenResult.errcode == ReturnCode.请求成功) { //更新用户Open id Cookie Response.Cookies.Add(new HttpCookie(WeChatOpenIdCookieName, accessTokenResult.openid)); //因为第一步选择的是OAuthScope.snsapi_userinfo,这里可以进一步获取用户详细信息 UserService userService = new UserService(); OAuthUserInfo userInfo = OAuthApi.GetUserInfo(accessTokenResult.access_token, accessTokenResult.openid); WeChatUser wechatUser = userService.GetWeChatUser(accessTokenResult.openid); if (wechatUser == null) { userService.WeChatUserSubscribe(accessTokenResult.openid, false, true); wechatUser = userService.GetWeChatUser(accessTokenResult.openid); } else { wechatUser.HasAuthorized = true; } if (wechatUser != null) { // Updates wechat user info wechatUser.AccessToken = accessTokenResult.access_token; wechatUser.AccessTokenExpired = false; wechatUser.AccessTokenExpireTime = DateTime.Now.AddSeconds(accessTokenResult.expires_in); wechatUser.City = userInfo.city; wechatUser.County = userInfo.country; wechatUser.NickName = userInfo.nickname; wechatUser.Photo = userInfo.headimgurl; wechatUser.Province = userInfo.province; wechatUser.Sex = userInfo.sex; if (userService.UpdateWeChatUser(wechatUser)) { //Updates current wechat user Session[WeChatUserInfo] = wechatUser; //LogService.LogWexin("保存微信用户资料成功", ""); isSuccessFul = true; } else { LogService.LogWexin("保存微信用户资料失败", wechatUser.OpenId); } } } } } catch (Exception ex) { LogService.LogWexin("QAuth获取用户信息失败", ex.ToString()); isSuccessFul = false; } if (isSuccessFul) { if (string.IsNullOrWhiteSpace(callBackUrl)) { callBackUrl = "/wechat/user/index"; } // 跳转到用户一开始要进入的页面 result = Redirect(callBackUrl); } else { // 授权失败,重新发发起用户授权 var redirectUrl = GetUrl("/wechat/QAuthCallBack/CallBack"); var appId = WeChatClient.App.AppId; var authUrl = OAuthApi.GetAuthorizeUrl(appId, redirectUrl, callBackUrl, OAuthScope.snsapi_userinfo); result = Redirect(authUrl); } return result; }
public ActionResult Index(int querytype = 0, int page = 1, string Keyword = "") { MemberViewModel viewModel = new MemberViewModel(); try { UserService service = new UserService(); int totalCount; int pageSize = 20; viewModel.UserList = service.QuersyUsers("-1", -1, page, pageSize, querytype, Keyword, out totalCount); viewModel.PageSize = pageSize; viewModel.PageStep = 5; viewModel.CurrentPage = page; viewModel.Keyword = Keyword; viewModel.QueryType = querytype; viewModel.TotalCount = totalCount; } catch (Exception ex) { LogService.Log("会员列表", ex.ToString()); } return View(viewModel); }