public async Task <ActionResult <CcCardReadModel> > Update(long id, CcCardUpdateModel updateModel, CancellationToken cancellationToken) { if (updateModel.Email != "") { var checkEmailExisted = _dbContext.Set <CcCard>().FirstOrDefault(p => p.Id != id && p.Email == updateModel.Email); if (checkEmailExisted != null) { return(BadRequest(new BaseResponseModel <object> { success = false, message = "Email is existed!", code = 400 })); } } string pass = updateModel.Uipass; var checkPass = Regex.IsMatch(pass, "^[0-9a-fA-F]{32}$", RegexOptions.Compiled); if (!checkPass) { updateModel.Uipass = NesopsUtil.GenerateMD5FromString(updateModel.Username + ":a2billing:" + pass); var sipUser = _dbContext.Set <CcSipBuddies>().FirstOrDefault(p => p.IdCcCard == id); string accountCode = sipUser.Accountcode; string md5secret = NesopsUtil.GenerateMD5FromString(accountCode + ":asterisk:" + pass); sipUser.Md5secret = md5secret; sipUser.Secret = ""; _dbContext.Set <CcSipBuddies>().Update(sipUser); await _dbContext.SaveChangesAsync(); } var readModel = await UpdateModel(id, updateModel, cancellationToken); return(Ok(new BaseResponseModel <CcCardReadModel> { message = "Update Successful", data = readModel, code = 404 })); }
public async Task <AuthenticationTicket> GetAuthenticateTicketAsync(string username, string password) { var user = await _dbContext.Set <CcCard>().AsNoTracking().FirstOrDefaultAsync(p => p.Username == username); if (user == null) { user = await _dbContext.Set <CcCard>().AsNoTracking().FirstOrDefaultAsync(p => p.Useralias == username); if (user == null) { return(null); } } if (user.Uipass != NesopsUtil.GenerateMD5FromString(user.Username + ":a2billing:" + password)) { return(null); } var identity = new ClaimsIdentity(); identity.AddClaim(new Claim(ClaimTypes.Name, user.Username)); identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id.ToString())); identity.AddClaim(new Claim(ClaimTypes.Role, "Customer")); var principal = new ClaimsPrincipal(identity); var prop = new AuthenticationProperties() { IssuedUtc = DateTime.UtcNow, ExpiresUtc = DateTime.UtcNow.AddDays(1) }; return(new AuthenticationTicket(principal, prop, "application")); }
public async Task <ActionResult <object> > GeneratePasswordForAccount(long id, CancellationToken cancellationToken) { var user = await _dbContext.Set <CcCard>().FirstOrDefaultAsync(p => p.Id == id); string pass = user.Uipass; var checkPass = Regex.IsMatch(pass, "^[0-9a-fA-F]{32}$", RegexOptions.Compiled); if (checkPass) { return(BadRequest(new BaseResponseModel <CcCard> { message = "This account has been generated password", data = user, code = 400 })); } if (user.Status != 1) { return(BadRequest(new BaseResponseModel <CcCard> { message = "This account is not activated", data = user, code = 400 })); } string md5password = NesopsUtil.GenerateMD5FromString(user.Username + ":a2billing:" + pass); user.Uipass = md5password; _dbContext.Set <CcCard>().Update(user); await _dbContext.SaveChangesAsync(); user = await _dbContext.Set <CcCard>().FirstOrDefaultAsync(p => p.Id == id); return(Ok(new BaseResponseModel <CcCard> { message = "Generate md5password for account successful", data = user, code = (int)HttpStatusCode.OK })); }
public async Task <ActionResult <object> > GenerateMD5ForAccount(long id, CancellationToken cancellationToken) { var user = _dbContext.Set <CcSipBuddies>().FirstOrDefault(p => p.Id == id); if (user == null) { return(null); } if (user.Secret == "" && user.Md5secret != "") { return(BadRequest(new BaseResponseModel <CcSipBuddies> { message = "This account has been generated md5secret", data = user, code = 400 })); } string secret = user.Secret; string accountCode = user.Accountcode; string md5secret = NesopsUtil.GenerateMD5FromString(accountCode + ":asterisk:" + secret); user.Md5secret = md5secret; user.Secret = ""; _dbContext.Set <CcSipBuddies>().Update(user); await _dbContext.SaveChangesAsync(); user = _dbContext.Set <CcSipBuddies>().FirstOrDefault(p => p.Id == id); return(Ok(new BaseResponseModel <CcSipBuddies> { message = "Generate md5secret for account successful", data = user, code = (int)HttpStatusCode.OK })); }
public async Task <ActionResult <object> > GenerateVoucher(VoucherGenerateModel model, CancellationToken cancellationToken) { int i = 1; IDictionary <string, string> result = new Dictionary <string, string>(); List <CcVoucher> listVoucher = new List <CcVoucher>(); var voucherTable = _dbContext.Set <CcVoucher>(); while (i <= model.quantity) { var checkExist = false; var voucherCode = ""; do { voucherCode = NesopsUtil.GetRandomStringNumber(15); checkExist = voucherTable.FirstOrDefault(p => p.Voucher == voucherCode) != null; } while (checkExist == true); result.Add("Code " + i, voucherCode); var voucher = new CcVoucher() { Activated = "t", Creationdate = DateTime.UtcNow.AddHours(7), Credit = model.credit, Currency = "USD", Expirationdate = model.exprireDate, Voucher = voucherCode }; listVoucher.Add(voucher); i++; } await voucherTable.AddRangeAsync(listVoucher, cancellationToken); await _dbContext.SaveChangesAsync(cancellationToken); return(Ok(new BaseResponseModel <IDictionary <string, string> > { message = "Generate Voucher Successful", data = result, code = (int)HttpStatusCode.OK })); }
public async Task <ActionResult <object> > GeneratePasswordForAllAccounts(CancellationToken cancellationToken) { var users = await _dbContext.Set <CcCard>().ToListAsync(); foreach (var user in users) { string pass = user.Uipass; var checkPass = Regex.IsMatch(pass, "^[0-9a-fA-F]{32}$", RegexOptions.Compiled); if (checkPass || user.Status != 1) { continue; } string md5password = NesopsUtil.GenerateMD5FromString(user.Username + ":a2billing:" + pass); user.Uipass = md5password; _dbContext.Set <CcCard>().Update(user); await _dbContext.SaveChangesAsync(); } users = await _dbContext.Set <CcCard>().ToListAsync(); return(Ok(new BaseResponseModel <List <CcCard> > { message = "Generate md5password for all account successful", data = users, code = (int)HttpStatusCode.OK })); }
public async Task <ActionResult <object> > GenerateMD5ForAllAccounts(CancellationToken cancellationToken) { var users = await _dbContext.Set <CcSipBuddies>().ToListAsync(); foreach (var user in users) { if (user.Secret == "" && user.Md5secret != "") { continue; } string secret = user.Secret; string accountCode = user.Accountcode; string md5secret = NesopsUtil.GenerateMD5FromString(accountCode + ":asterisk:" + secret); user.Md5secret = md5secret; user.Secret = ""; _dbContext.Set <CcSipBuddies>().Update(user); await _dbContext.SaveChangesAsync(); } users = await _dbContext.Set <CcSipBuddies>().ToListAsync(); return(Ok(new BaseResponseModel <List <CcSipBuddies> > { message = "Generate md5secret for all account successful", data = users, code = (int)HttpStatusCode.OK })); }