public AuthenticateResponse Authenticate(AuthenticateRequest model, string ipAddress) { var account = _context.Accounts.SingleOrDefault(x => x.Email == model.Email); if (account == null || !account.IsVerified || !BC.Verify(model.Password, account.PasswordHash)) { throw new AppException("Email or password is incorrect"); } // authentication successful so generate jwt and refresh tokens var jwtToken = generateJwtToken(account); var refreshToken = generateRefreshToken(ipAddress); account.RefreshTokens.Add(refreshToken); // remove old refresh tokens from account removeOldRefreshTokens(account); // save changes to db _context.Update(account); _context.SaveChanges(); var response = _mapper.Map <AuthenticateResponse>(account); response.JwtToken = jwtToken; response.RefreshToken = refreshToken.Token; return(response); }
public async Task <IActionResult> UpdateUser(int id, [Bind("Id,Name,Surname,PhoneNumber,TimeOfArrival,Transactions,Payment,EmployeeId")] EmployeesUser employeesUser) { if (id != employeesUser.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(employeesUser); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeesUserExists(employeesUser.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("DetailsUser", new { id = employeesUser.EmployeeId })); } ViewData["EmployeeId"] = new SelectList(_context.Employees, "Id", "Id", employeesUser.EmployeeId); return(RedirectToAction("DetailsUser", new { id = employeesUser.EmployeeId })); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Price,Description,StoreModelId")] Product product) { if (id != product.Id) { return(NotFound()); } if (ModelState.IsValid) { try { var user = await _userManager.GetUserAsync(HttpContext.User); var store = _context.Stores.Where(i => i.UserId == user.Id).FirstOrDefault(); product.StoreModelId = store.Id; _context.Update(product); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(product.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["StoreModelId"] = new SelectList(_context.Stores, "Id", "Address", product.StoreModelId); return(View(product)); }
public async Task <IActionResult> Edit(Guid id, [Bind("VolumeID,UserID,Tag,CreateTime,LastModifiedTime")] Image image) { if (id != image.VolumeID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(image); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ImageExists(image.VolumeID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["UserID"] = new SelectList(_context.Users, "Id", "Id", image.UserID); return(View(image)); }
public void Update <T>(T entity) where T : class => _Context.Update(entity);