public async Task <ActionResult> ChangeNickName([FromBody] ChangeNickNameFromData data) { ApiStatusModel <string> status = new ApiStatusModel <string>(); try { if (data.nickname.Trim().Length < 3 || data.nickname.Trim().Length > 10) { status.statecode = "fail"; status.content = "昵称长度为3至10位"; return(new JsonResult(status)); } if (await _iuser.ChangeNickName(GetUserId(), data.nickname.Trim())) { status.statecode = "ok"; status.content = "昵称修改成功"; return(new JsonResult(status)); } status.statecode = "fail"; status.content = "昵称修改失败"; return(new JsonResult(status)); } catch (Exception err) { _logger.LogError(err.Message + err.StackTrace); status.statecode = "error"; status.content = "联系管理员"; return(new JsonResult(status)); } }
public ActionResult <ApiStatusModel> Get() { ApiStatusModel version = new ApiStatusModel(); version.App_name = Configurator.AppName; version.Version = Configurator.Version; version.Update_date = Configurator.AppUpdate; version.Envoloment = Configurator.EnvironmentName; version.DateTime = DateTime.Now; return(version); }
public async Task <ActionResult> FindPassWord([FromBody] FindPassWordFromData data) { ApiStatusModel <string> sysModel = new ApiStatusModel <string>(); try { if (data.password.Length < 6 || data.password.Length > 16) { sysModel.statecode = "fail"; sysModel.content = "密码(长度6至16位)"; return(new JsonResult(sysModel)); } string code = await _uCache.GetMobileValidateCode(data.mobile); if (code == null) { sysModel.statecode = "fail"; sysModel.content = "验证码过期"; return(new JsonResult(sysModel)); } if (code == null || code != data.validataCode) { sysModel.statecode = "fail"; sysModel.content = "验证码错误"; return(new JsonResult(sysModel)); } if (await _iuser.ChangePwdByMoible(data.mobile, Encrypt.LoginPwd(data.password))) { sysModel.statecode = "ok"; sysModel.content = "修改成功"; await _uCache.RemoveMobileValidateCode(data.mobile); } return(new JsonResult(sysModel)); } catch (Exception err) { _logger.LogError("修改密码:" + err.Message + err.StackTrace); sysModel.statecode = "fail"; sysModel.content = "联系管理员"; return(new JsonResult(sysModel)); } }
public async Task <ActionResult> GetUserInfo() { try { long userid = GetUserId(); ApiStatusModel <UserShowModel> stasus = new ApiStatusModel <UserShowModel>(); //object obj = await _uCache.GetUserInfoTest(userid); //_logger.LogError(obj.ToString(), obj); UserShowModel uEntity = await _uCache.GetUserInfo(userid); if (uEntity != null) { stasus.content = uEntity; stasus.statecode = "ok"; return(new JsonResult(stasus)); } uEntity = await _iuser.GetUserModel(userid); if (uEntity != null) { stasus.content = uEntity; stasus.statecode = "ok"; await _uCache.SaveUserInfo(userid, uEntity); } else { stasus.statecode = "fail"; } return(new JsonResult(stasus)); } catch (Exception err) { _logger.LogError(err.Message + err.StackTrace); ApiStatusModel <string> uEntity = new ApiStatusModel <string>(); uEntity.statecode = "error"; uEntity.content = "联系管理员"; return(new JsonResult(uEntity)); } }
public async Task <ActionResult> ChangeHeaderPortrait([FromBody] ChangeHeaderPortraitFromData data) { ApiStatusModel <string> status = new ApiStatusModel <string>(); try { string base64 = data.base64.Replace("data:image/jpeg;base64,", "").Replace("data:image/png;base64,", ""); string filePath = Base64StringToImage(base64, @"\profile\userheader\" + DateTime.Now.ToString("yyyyMMdd") + "\\", _config.uploadUserHeaderPortraitPhysicsPath); if (filePath == "") { status.statecode = "fail"; status.content = "上传失败,检查头像格式"; return(new JsonResult(status)); } long userid = GetUserId(); Thumbnail thm = new Thumbnail(); if (thm.SetImage(_config.uploadUserHeaderPortraitPhysicsPath + "\\" + filePath)) { thm.SaveThumbnailImage(250, 250, true); } if (await _iuser.ChangeHeaderPic(userid, filePath)) { status.statecode = "ok"; status.content = filePath; await _uCache.RemoveUserInfo(userid); } else { status.statecode = "fail"; status.content = "上传失败"; } return(new JsonResult(status)); } catch (Exception err) { _logger.LogError(err.Message + err.StackTrace); status.statecode = "error"; status.content = "联系管理员"; return(new JsonResult(status)); } }
public async Task <ActionResult> ChangePassWord([FromBody] ChangePassWordFromData data) { ApiStatusModel <string> status = new ApiStatusModel <string>(); try { if (data.newpwd.Trim().Length < 6 || data.newpwd.Trim().Length > 16) { status.statecode = "fail"; status.content = "密码长度为6至16位"; return(new JsonResult(status)); } if (data.oldpwd == data.newpwd) { status.statecode = "fail"; status.content = "旧密码和新密码不能相同"; return(new JsonResult(status)); } if (!await _iuser.ValidateOldPwd(GetUserId(), Encrypt.LoginPwd(data.oldpwd.Trim()))) { status.statecode = "fail"; status.content = "旧密码不正确"; return(new JsonResult(status)); } if (await _iuser.ChangePwd(GetUserId(), Encrypt.LoginPwd(data.newpwd.Trim()))) { status.statecode = "ok"; status.content = "密码修改成功"; return(new JsonResult(status)); } status.statecode = "fail"; status.content = "密码修改失败"; return(new JsonResult(status)); } catch (Exception err) { _logger.LogError(err.Message + err.StackTrace); status.statecode = "error"; status.content = "联系管理员"; return(new JsonResult(status)); } }
private async Task <ApiStatusModel <string> > SendValidataCode(string mobile, string signName, string templateCode) { ApiStatusModel <string> sysModel = new ApiStatusModel <string>(); int id = new Random().Next(10000, 99999); string result = "短信api"; if (result.IndexOf("1,") != -1) { await _uCache.SaveMobileValidateCode(mobile, id.ToString()); //ValidateCodeCache.SaveMobileCode(mobile, id); sysModel.statecode = "ok"; sysModel.content = "发送成功"; return(sysModel); } else { sysModel.statecode = "fail"; sysModel.content = result; return(sysModel); } }
public async Task <ActionResult> Register([FromBody] UserRegisterFromData data) { ApiStatusModel <string> sysModel = new ApiStatusModel <string>(); try { if (data.mobile == null || data.mobile.Length == 0) { sysModel.statecode = "fail"; sysModel.content = "手机号不能为空"; return(new JsonResult(sysModel)); } if (data.password == null || data.password.Length == 0) { sysModel.statecode = "fail"; sysModel.content = "密码不能为空"; return(new JsonResult(sysModel)); } if (data.password.Length < 6 || data.password.Length > 16) { sysModel.statecode = "fail"; sysModel.content = "密码(长度6至16位)"; return(new JsonResult(sysModel)); } if (data.validatecode == null || data.validatecode.Length == 0) { sysModel.statecode = "fail"; sysModel.content = "验证码不能为空"; return(new JsonResult(sysModel)); } if (await _iuser.CheckMobileIsExist(data.mobile)) { sysModel.statecode = "fail"; sysModel.content = "手机号码已经被注册"; return(new JsonResult(sysModel)); } string code = await _uCache.GetMobileValidateCode(data.mobile); if (code == null) { sysModel.statecode = "fail"; sysModel.content = "验证码过期"; return(new JsonResult(sysModel)); } if (code != data.validatecode) { sysModel.statecode = "fail"; sysModel.content = "验证码错误"; return(new JsonResult(sysModel)); } UserRegisterModel entity = new UserRegisterModel(); entity.LoginName_Mobile = data.mobile; entity.nickname = new Random().Next(99999, 999999).ToString(); entity.UserKey = Guid.NewGuid().ToString().Replace("-", ""); entity.PassWord = Encrypt.LoginPwd(data.password); entity.CreateDate = DateTime.Now; entity.RegIP = data.ip; entity.UsersID = await _iuser.GetUserIdRandom(); entity.headerpic = "/content/images/logo1.png"; if (await _iuser.RegisterUser(entity)) { await _iuser.ChangeUserIdRandom(entity.UsersID); sysModel.statecode = "ok"; sysModel.content = "注册成功"; await _uCache.RemoveMobileValidateCode(data.mobile); return(new JsonResult(sysModel)); } else { sysModel.statecode = "fail"; sysModel.content = "注册失败"; return(new JsonResult(sysModel)); } } catch (Exception err) { _logger.LogError("用户注册:" + err.Message + err.StackTrace); sysModel.statecode = "fail"; sysModel.content = "联系管理员"; return(new JsonResult(sysModel)); } }
public async Task <ActionResult> GetMobileValidateCode([FromBody] MobileValidateCodeFromData data) { ApiStatusModel <string> sysModel = new ApiStatusModel <string>(); try { if (data.mobile == null || data.mobile.Length != 11) { sysModel.statecode = "fail"; sysModel.content = "手机号码不正确"; return(new JsonResult(sysModel)); } DateTime dtime = DateTime.Now; if (!DateTime.TryParse(data.requestTime, out dtime)) { sysModel.statecode = "fail"; sysModel.content = "请求时间格式不正确"; return(new JsonResult(sysModel)); } TimeSpan tsp = DateTime.Now - dtime; if (tsp.TotalMinutes > 10) { sysModel.statecode = "fail"; sysModel.content = "请求时间格,超时"; return(new JsonResult(sysModel)); } if (Encrypt.GetMD5(_config.client + data.requestTime + _config.secret + data.fromdevice) != data.md5) { sysModel.statecode = "fail"; sysModel.content = "非法操作"; return(new JsonResult(sysModel)); } if (data.doaction == "注册") { sysModel = await SendValidataCode(data.mobile, "注册验证", "SMS_4735597"); } else if (data.doaction == "找回密码") { bool isExist = await _iuser.CheckMobileIsExist(data.mobile); if (!isExist) { sysModel.statecode = "fail"; sysModel.content = "账号未注册,请注册"; return(new JsonResult(sysModel)); } sysModel = await SendValidataCode(data.mobile, "乐居乐家", "SMS_4735600"); } else { sysModel.statecode = "fail"; sysModel.content = "重新获取"; } return(new JsonResult(sysModel)); } catch (Exception err) { _logger.LogError("设备:" + (data != null ? data.fromdevice : "") + "获取验证码:" + err.Message + err.StackTrace); sysModel.statecode = "fail"; sysModel.content = "联系管理员"; return(new JsonResult(sysModel)); } }