public ActionResult Auth(AuthorizeVM model) { var isAuthorizeSuccess = false; DateTime?Deadline = null; var bll = base.CreateBusiness <IAuthBusiness>(); if (ModelState.IsValid) { isAuthorizeSuccess = bll.AuthorizePlat(model);//调用业务层 验证授权码 AuthorizeResultVM authResult = new AuthorizeResultVM(); authResult.isAuthorizeSuccess = isAuthorizeSuccess; if (isAuthorizeSuccess) { PlatformAuthorizeHelper helper = new PlatformAuthorizeHelper(); Deadline = helper.GetAuthorizedDeadline(model.AuthorizeCode); authResult.AuthorizeDeadline = Deadline; return(View("AuthorizeResult", authResult)); } else { return(View("AuthorizeResult", authResult)); } } else { //todo:等父类 加了warning 提示,把error 换成warning return(base.Error("未通过验证")); } }
public async Task <int> AddAuthorizationRecordAsync(AuthorizeVM vm) { var RecordDb = this._dbContext.Set <AuthorizationRecord>(); var firstRecord = await RecordDb.AsNoTracking().Where(t => t.IsDeleted == false && t.AuthorizeCode == vm.AuthorizeCode).FirstOrDefaultAsync(); if (firstRecord != null) { return(-1); } var record = new AuthorizationRecord() { AuthorizeCode = vm.AuthorizeCode, AuthorizedTimespan = vm.AuthorizedTimespan.ToString(), CreateDate = DateTime.Now, IsDeleted = false, MachineCode = vm.MachineCode, TimespanMonth = vm.TimespanMonth }; await RecordDb.AddAsync(record); int row = await this._dbContext.SaveChangesAsync(); return(row); }
// GET: Authorize 授权页面 public ActionResult Register() { PlatformAuthorizeHelper helper = new PlatformAuthorizeHelper(); AuthorizeVM model = new AuthorizeVM(); model.MachineCode = helper.GetMachineCode(); #if DEBUG model.AuthorizeCode = helper.GetAuthorizeCode(model.MachineCode, new TimeSpan(354, 0, 0, 0, 0)); #endif return(View(model)); }
/// <summary> /// 传入平台识别码,和授权码,并核对平台识别码是否合法,并且授权码是否可用,则写入授权码到服务器根目录文件。 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool AuthorizePlat(AuthorizeVM model) { var isAuthorize = false; PlatformAuthorizeHelper helper = new PlatformAuthorizeHelper(); var MachineCode = helper.GetMachineCode(); if (MachineCode == model.MachineCode) { isAuthorize = helper.CheckPlatformIsAuthorize(model.AuthorizeCode);//如果授权码可用 if (isAuthorize) { helper.WriteAuthorizeToConfig(model.AuthorizeCode); } } return(isAuthorize); }
public async Task <IActionResult> KeyGeneratorResultAsync(AuthorizeVM model) { model.AuthorizedTimespan = DateTime.Now.AddMonths(model.TimespanMonth) - DateTime.Now; model.AuthorizeCode = this.AuthService.GenerateAuthorizationCode(model.MachineCode, model.AuthorizedTimespan); try { int row = await AuthService.AddAuthorizationRecordAsync(model); } catch (System.Data.SqlClient.SqlException ex) { //await LogHelper.LogErrorAsync(new Domain.Entity.LogInfo() //{ // Title = "同一用户注册,保存数据库异常:", // Tag = "AuthorizeController/KeyGeneratorResultAsync" //}, ex); } //await LogHelper.logInfoAsync(new Domain.Entity.LogInfo() { OrdinaryInfo = model, Title = "同一用户注册成功:", Tag = "AuthorizeController/KeyGeneratorResultAsync" }); return(Json(model)); }