public async Task <IActionResult> LoginViaPass(string username, string password) { if (!ValidateHelper.IsAllNotEmpty(username, password)) { return(GetJsonRes("用户名密码不能为空")); } var res = await this._login.ValidUserPassword(username, password); res.ThrowIfNotSuccess(); var user = res.Data; var identity = new IdentityServer4.IdentityServerUser(user.UID) { DisplayName = user.UserName }; identity.AdditionalClaims = new Claim[] { new Claim(AuthExtensions.claims_account_type_key, "user") }; await this.HttpContext.SignInAsync(identity); return(GetJson(new _().SetSuccessData(string.Empty))); }
public async Task <IActionResult> LoginViaPass([FromForm] string username, [FromForm] string password) { if (!ValidateHelper.IsAllNotEmpty(username, password)) { return(GetJsonRes("用户名密码不能为空")); } var admin = await this._login.GetUserByUserName(username); if (admin == null) { return(GetJsonRes("用户不存在")); } if (admin.PassWord != this._login.EncryptPassword(password)) { return(GetJsonRes("密码错误")); } var scheme = ConfigSet.Identity.AdminLoginScheme; var principal = admin.ToPrincipal(scheme, x => x.SetAccountType("admin").SetCreateTimeUtc()); await this.HttpContext.SignInAsync(principal, new AuthenticationProperties() { }); return(SuccessJson()); }
/// <summary> /// 用@分割邮件地址 /// </summary> /// <param name="email"></param> /// <returns></returns> public static (string user_name, string host) SplitEmail(this string email) { var sp = email.Split('@'); if (sp.Length != 2 || !ValidateHelper.IsAllNotEmpty(sp[0], sp[1])) { throw new ArgumentException("邮件格式错误"); } return(sp[0], sp[1]); }
public async Task <IActionResult> ResetPwd([FromForm] string user_uid, [FromForm] string pwd) { if (!ValidateHelper.IsAllNotEmpty(user_uid, pwd)) { throw new NoParamException(); } await this._login.SetPassword(user_uid, pwd); return(SuccessJson()); }
public async Task <IActionResult> RemoveOwner(string org_uid, string user_uid) { if (!ValidateHelper.IsAllNotEmpty(org_uid, user_uid)) { throw new NoParamException(); } var loginuser = await this.GetLoginAdminAsync(); await this._orgService.RemoveOwner(org_uid, user_uid); return(SuccessJson()); }
public async Task <IActionResult> SetUserIdCard([FromServices] IUserService userService, [FromForm] string code, [FromForm] string idcard, [FromForm] string real_name) { code = "暂时不用"; if (!ValidateHelper.IsAllNotEmpty(code, idcard, real_name)) { return(GetJsonRes("请输入完整信息")); } if (!Regex.IsMatch(idcard, @"^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$", RegexOptions.IgnoreCase)) { return(GetJsonRes("请输入正确的身份证号码")); } var loginuser = await this.GetLoginUserAsync(); var data = await this._login.GetUserPhone(loginuser.UserID); var phone = data.FirstOrDefault()?.Phone; if (ValidateHelper.IsEmpty(phone)) { return(GetJsonRes("用户未绑定手机,无法实名制")); } var after = DateTime.UtcNow.AddMinutes(-5); var code_model = await this._login.GetValidationCode(x => x.UserUID == loginuser.UserID && x.Phone == phone && x.Code == code && x.CreateTimeUtc > after && x.CodeType == id_confirm_sms_type); if (code_model == null) { //return GetJsonRes("验证码错误"); } var res = await userService.SetIdCard(loginuser.UserID, idcard, real_name); res.ThrowIfNotSuccess(); var key = this.cacheKeyManager.UserLoginInfo(loginuser.UserID); await this.cacheProvider.RemoveAsync(key); return(SuccessJson()); }
private async Task GetEndpointData(string path) { if (!this.IsEndpointLevel(path)) { return; } try { var bs = await this.Client.GetDataOrThrow_(path, this._node_watcher); if (ValidateHelper.IsEmpty(bs)) { await this.Client.DeleteNodeRecursively_(path); return; } var data = this._serializer.Deserialize <AddressModel>(bs) ?? throw new ArgumentNullException("序列化address model错误"); if (!ValidateHelper.IsAllNotEmpty(data.ServiceNodeName, data.EndpointNodeName, data.Url)) { throw new ArgumentException($"address model数据错误:{data.ToJson()}"); } var service_info = this.GetServiceAndEndpointNodeName(path); data.ServiceNodeName = service_info.service_name; data.EndpointNodeName = service_info.endpoint_name; this._endpoints.RemoveWhere_(x => x.FullPathName == data.FullPathName); this._endpoints.Add(data); if (this.OnServiceChangedAsync != null) { await this.OnServiceChangedAsync.Invoke(); } } catch (Exception e) { this.logger.AddErrorLog($"读取节点数据失败:{path}", e); } }
public async Task <IActionResult> ChangePwd([FromForm] string old_pwd, [FromForm] string pwd) { if (!ValidateHelper.IsAllNotEmpty(old_pwd, pwd)) { throw new NoParamException(); } var loginadmin = await this.GetLoginAdminAsync(); var admin = await this._login.GetUserByUID(loginadmin.UserID); admin.Should().NotBeNull(); if (admin.PassWord != this._login.EncryptPassword(old_pwd)) { return(GetJsonRes("旧密码不匹配")); } await this._login.SetPassword(admin.Id, pwd); return(SuccessJson()); }
/// <summary> /// 判断是否都是非空字符串 /// </summary> /// <param name="arr"></param> /// <returns></returns> public static bool IsAllPlumpString(this IEnumerable <string> arr) => ValidateHelper.IsAllNotEmpty(arr.ToArray());
public override async Task OnActionExecutionAsync(ActionExecutingContext _context, ActionExecutionDelegate next) { var config = _context.HttpContext.RequestServices.ResolveConfig_(); var salt = config[ConfigKey]; if (ValidateHelper.IsEmpty(salt)) { throw new ConfigNotExistException($"没有配置签名的约定key({ConfigKey})"); } var context = _context.HttpContext; var allparams = context.PostAndGet(); #region 验证时间戳 var client_timestamp = ConvertHelper.GetInt64(allparams.GetValueOrDefault("timestamp") ?? "-1", -1); if (client_timestamp < 0) { _context.Result = new JsonResult(new _() { }.SetErrorMsg("缺少时间戳")); return; } var server_timestamp = DateTimeHelper.GetTimeStamp(); //取绝对值 if (Math.Abs(server_timestamp - client_timestamp) > Math.Abs(DeviationSeconds)) { _context.Result = new JsonResult(new _() { }.SetSuccessData(new { client_timestamp, server_timestamp }).SetErrorMsg("请求时间戳已经过期")); return; } #endregion #region 验证签名 var client_sign = ConvertHelper.GetString(allparams.GetValueOrDefault(SignKey)).ToUpper(); if (!ValidateHelper.IsAllNotEmpty(client_sign)) { _context.Result = new JsonResult(new _() { }.SetErrorMsg("请求被拦截,获取不到签名")); return; } var reqparams = SignHelper.FilterAndSort(allparams, SignKey, new MyStringComparer()); var(server_sign, sign_data) = SignHelper.CreateSign(reqparams, salt); if (client_sign != server_sign) { _context.Result = new JsonResult(new _() { }.SetSuccessData(new { server_sign, client_sign, sign_data }).SetErrorMsg("签名错误")); return; } #endregion await next.Invoke(); }