public IActionResult Authenticate([FromBody] MedicViewModel userVM) { var user = _userService.Authenticate(userVM.Cpf, userVM.Password); if (user == null) { return(BadRequest(new { message = "Senha ou Cpf incorretos" })); } var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_appSettings.Secret); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, user.ID.ToString()), new Claim(ClaimTypes.Role, user.GetType().Name) }), Expires = DateTime.UtcNow.AddDays(1), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); var tokenString = tokenHandler.WriteToken(token); // return basic user info (without password) and token to store client side return(Ok(new { Id = user.ID, Cpf = user.Cpf, Name = user.Name, Crm = user.Crm, Token = tokenString })); }
public async Task <IActionResult> Medic() { var user = await _userManager.GetUserAsync(User); var model = new MedicViewModel(); if (user.HealthPoints == user.MaxHealthPoints) { model.FullHealth = true; } return(View(model)); }
public ActionResult Post([FromBody] MedicViewModel userVM) { var user = _mapper.Map <Medic>(userVM); try { _userService.Create(user, userVM.Password); return(Ok()); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }
public RegisterMedicViewModel() { MedicViewModel = new MedicViewModel(); InstitutiiAsociate = new ObservableCollection <InstitutieAsociata>(); HandleRegisterCommand = new BasicCommandWithParameter(Register); var institutii = AppService.Instance.InstitutieAsociataService.GetAll(); institutii.ToList().ForEach(x => { InstitutiiAsociate.Add(x); }); InstitutieSelectata = InstitutiiAsociate[0]; }
public ActionResult Put(int id, [FromBody] MedicViewModel userVM) { // map dto to entity and set id var user = _mapper.Map <Medic>(userVM); user.ID = id; try { // save _userService.Update(user, userVM.Password); return(Ok()); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
public async Task <IActionResult> Medic(MedicViewModel model) { if (ModelState.IsValid) { var user = await _userManager.GetUserAsync(User); if (user.Status != UserStatus.Stays) { ModelState.AddModelError(string.Empty, "Aktualnie nie możesz się uleczyć."); } else if (model.Points < 1) { ModelState.AddModelError(string.Empty, "Podano nieprawidłową wartość."); } else if (model.Points > user.MaxHealthPoints - user.HealthPoints) { ModelState.AddModelError(string.Empty, "Podano za dużą wartość."); } else if (model.Points * 10 > user.Gold) { ModelState.AddModelError(string.Empty, "Nie masz tyle złota."); } else { user.Gold -= (int)model.Points * 10; user.HealthPoints += (int)model.Points; await _userManager.UpdateAsync(user); } if (user.HealthPoints == user.MaxHealthPoints) { model.FullHealth = true; } } return(View(model)); }
public MedicWindowActions(MedicViewModel medicVM) { this.medicVM = medicVM; }