public async void Initialize() { if (!_context.Block.Any()) { await _context.Block.AddAsync(getGenesisBlock()); await _context.SaveChangesAsync(); } if (!_context.Roles.Any()) { await _context.Roles.AddRangeAsync( new Role { RoleId = 1, Name = "User" }, new Role { RoleId = 2, Name = "Doctor" }, new Role { RoleId = 3, Name = "Admin" }); await _context.SaveChangesAsync(); } }
public async Task <IActionResult> Add([FromQuery] string token) { var user = await _context.User.FirstOrDefaultAsync(u => u.token == token); if (user != null) { var model = new MedicalModel(); model.Hash = user.Hash; user.token = await ShaEncoder.GenerateSHA256String($"{user.Login}{user.Password}{DateTime.Now}"); _context.User.Update(user); await _context.SaveChangesAsync(); var codeGenerator = new QRCodeGenerator(); var webRootPath = _hostingEnvironment.WebRootPath; var medicalQRCode = new QRCode(codeGenerator.CreateQrCode( $"http://blockchain.whisperq.ru/medical/add?token={user.token}", QRCodeGenerator.ECCLevel.Q)); var medicalQRImage = medicalQRCode.GetGraphic(10, Color.Black, Color.White, (Bitmap)Image.FromFile($"{webRootPath}/images/piedPiper.png")); medicalQRImage.Save($"{webRootPath}/images/QR/{user.Login}.jpg"); return(View(model)); } return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> Add(string hash_сustomer, string hash_executor, string order_sum, string prepaid_expense, string condition, string is_Done, string is_freze) { var is_Done_bool = String2Bool.Convert(is_Done); var is_freze_bool = String2Bool.Convert(is_Done); User user = null; Transactions transactions = null; if (ModelState.IsValid) { user = await _context.User.FirstOrDefaultAsync(u => u.Login == User.Identity.Name); if (user != null) { if (user.balance >= Convert.ToDouble(order_sum)) { string contract_hash = await ShaEncoder.GenerateSHA256String($"{order_sum}{prepaid_expense}{DateTime.Now}"); var contract = new Contract { hash_сustomer = user.Hash, hash_еxecutor = hash_executor, order_sum = Convert.ToInt32(order_sum) - Convert.ToInt32(prepaid_expense), prepaid_expense = prepaid_expense, is_freze = true, is_Done = false, contractID = contract_hash }; var json = JsonConvert.SerializeObject(contract); await _blockchainService.AddBlockAsync(await _blockchainService.generateNextBlockAsync(json, user.Hash, hash_executor)); transactions = new Transactions { original_wallet = user.Hash, destination_wallet = hash_executor, info = json, timestamp = DateTime.Now.ToString() }; user.balance = Convert.ToInt16(prepaid_expense); _context.User.Update(user); await _context.Transactions.AddAsync(transactions); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Home")); } return(Content("Недостаточно средств")); } ModelState.AddModelError("", "Некорректные логин и(или) пароль"); } return(View()); }
public async Task <IActionResult> Index(string site, string organisation) { var user = await _context.User.FirstOrDefaultAsync(u => u.Login == User.Identity.Name); var api = new API { is_active = true, site = site, organisation = organisation, timestamp = DateTime.Now.ToString(), token = await ShaEncoder.GenerateSHA256String($"{site}{organisation}{DateTime.Now}") }; await _context.Api.AddAsync(api); await _context.SaveChangesAsync(); return(Content("Token: " + api.token)); }
public async Task <IActionResult> Register(RegisterModel model) { if (ModelState.IsValid) { var user = await _context.User.FirstOrDefaultAsync(u => u.Login == model.login); if (user == null) { user = new User { Login = model.login, Password = await ShaEncoder.GenerateSHA256String(model.password), type_of_bloud = model.type_of_blood, Hash = await ShaEncoder.GenerateSHA256String($"{model.login}{model.password}{model.code_phrase}"), token = await ShaEncoder.GenerateSHA256String($"{model.login}{model.password}{DateTime.Now}") }; var userRole = await _context.Roles.FirstOrDefaultAsync(r => r.Name == "User"); if (userRole != null) { user.Role = userRole; } _context.User.Add(user); await _context.SaveChangesAsync(); GenerateUserQRCodes(user); await Authenticate(user); return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("", "Некорректные логин и(или) пароль"); } return(View(model)); }