public async Task<string> Post(MAppInfoPwd mo) { Result<string> res = new Result<string>(); try { var configPWD = AppConfigurtaionServices.Configuration.GetSection("PwdOfApp").Value; var sign = Encrypt.HmacSHA256(configPWD, configPWD); if (!sign.Equals(mo.pwd)) { res = new Result<string>(ResultCode.LoginFail, null, null); } else { Guid appID_tmp; if (!Guid.TryParse(mo.appID, out appID_tmp)) { res = new Result<string>(ResultCode.Fail, "appID must be a GUID.", ""); } else { MAppInfo mot = new MAppInfo(); mot.id = mo.id; mot.note = mo.note; mot.secretKey = mo.secretKey; mot.appName = mo.appName; mot.appID = mo.appID; mot.addTime = mo.addTime; BAppInfo bll = new BAppInfo(connStr); var re = await bll.InsertOne(mot); res = new Result<string>(re ? ResultCode.Ok : ResultCode.Fail, null, re.ToString()); } } return JsonConvert.SerializeObject(res); } catch (Exception ex) { res = new Result<string>(ResultCode.Fail, ex.Message, null); return JsonConvert.SerializeObject(res); } }
/// <summary> /// Add One App /// </summary> /// <param name="mo"></param> /// <returns></returns> public async Task <bool> InsertOne(MAppInfo mo) { bool res = false; string appID = mo.appID; string appName = mo.appName; string note = mo.note; string secretKey = mo.secretKey; if (SqlAttack.IsDangerous(ref appID) || SqlAttack.IsDangerous(ref appName) || SqlAttack.IsDangerous(ref note) || SqlAttack.IsDangerous(ref secretKey)) { return(res); } StringBuilder sb = new StringBuilder(); sb.Append("INSERT INTO `AppInfo` (id,appID,appName,addTime,secretKey,note) VALUES ("); sb.Append("@id, @appID, @appName, @addTime, @secretKey, @note"); sb.Append(")"); using (var conn = new MySqlConnection(connStr)) { var re = await conn.ExecuteAsync(sb.ToString(), new { id = 0, appID = mo.appID.Trim(), appName = mo.appName.Trim(), addTime = mo.addTime, secretKey = mo.secretKey, note = mo.note }); if (re > 0) { res = true; } return(res); } }