public async Task<string> Verfiy(User user) { if (user == null) { return "未获取用户!"; } if (string.IsNullOrEmpty(user.Alias) && user.Alias != user.Id.ToString()) { return "必须先开通博客,才能申请JS权限!"; } var applyStatus = await _jsPermissionApplyRepository.GetInvalid(user.Id).Select(x => x.Status).FirstOrDefaultAsync(); if (applyStatus == Status.Pass) { return "您的JS权限申请已开通,请勿重复申请!"; } if (applyStatus == Status.Wait) { return "您的JS权限申请正在处理中,请稍!"; } if (applyStatus == Status.Lock) { return "您暂时无法申请JS权限,请联系[email protected]"; } return string.Empty; }
public async Task ApplyWithScriptTest() { var user = new User { Alias = "xishuai", DisplayName = "田园里的蟋蟀", Email = "*****@*****.**", LoginName = "田园里的蟋蟀", Id = 435188 }; var verfiyResult = await _applyAuthenticationService.Verfiy(user); Console.WriteLine(verfiyResult); Assert.Empty(verfiyResult); var jsPermissionApply = new JsPermissionApply("我要申请JS权限<script>console.log(111)</script>", user, ""); _unitOfWork.RegisterNew(jsPermissionApply); Assert.True(await _unitOfWork.CommitAsync()); }
public JsPermissionApply(string reason, User user, string ip) { if (string.IsNullOrEmpty(reason)) { throw new ArgumentException("申请内容不能为空"); } if (reason.Length > 3000) { throw new ArgumentException("申请内容超出最大长度"); } if (user == null) { throw new ArgumentException("用户为null"); } if (user.Id == 0) { throw new ArgumentException("用户Id为0"); } this.Reason = HttpUtility.HtmlEncode(reason); this.User = user; this.Ip = ip; this.Status = Status.Wait; }