public void AddMessageToRoomTestAsync() { var user = new UserAccountDTO() { Login = "******", Password = "******" }; var user1 = new User() { Login = "******", Password = "******" }; var appContext = new Mock <ApplicationContext>(); var map = new Mock <IMapper>(); var email = new Mock <IEmailService>(); var service = new UsersService(map.Object, appContext.Object, email.Object); User user11 = null; var mock = new Mock <IUsersService>(); mock.Setup(x => x.Authenticate(user.Login, user.Password)).ReturnsAsync(user); mock.Setup(x => x.GetUserByLogin(user.Login)).ReturnsAsync(user1); mock.Setup(x => x.GetUserByLogin(user1.Login)).ReturnsAsync(user11); var result = service.Authenticate(user.Login, user.Password); Assert.Equal(user.Login, user.Login); mock.Verify(); }
//change password public IHttpActionResult ChangePassword(ChangePassword objChangePassword) { UserAccountDTO objUserAccount = db.GetUserAccountInfoByUserID(objChangePassword.UserID); if (objUserAccount != null && !string.IsNullOrEmpty(objChangePassword.UserAccountPassword)) { byte[] passwordInByteArray = Encoding.ASCII.GetBytes(objChangePassword.CurrentPassword); byte[] dbPassword = objUserAccount.Password; bool areEqual = passwordInByteArray.SequenceEqual(dbPassword); if (areEqual) { ChangePassword objchange = new ChangePassword(); objchange.UserAccountUserName = objUserAccount.UserName; objchange.UserID = objUserAccount.UserID; objchange.UserAccountPassword = objChangePassword.UserAccountPassword; objchange.UserAccountID = objChangePassword.UserAccountID; db.ChangePassword(objchange); return(Ok()); } else { return(Json("MisMatch")); } } else { return(NotFound()); } }
public ResponseDTO <UserAccountDTO> SetRole(UserAccountDTO newAccountInfo) { ResponseDTO <UserAccountDTO> response = new ResponseDTO <UserAccountDTO>(); using (var dbContextTransaction = context.Database.BeginTransaction()) { try { var currentUser = (from users in context.UserAccounts where users.Id == newAccountInfo.Id select users).FirstOrDefault(); currentUser.RoleType = newAccountInfo.RoleType; context.SaveChanges(); dbContextTransaction.Commit(); response.Data = new UserAccountDTO(currentUser); return(response); } catch { dbContextTransaction.Rollback(); response.Data = null; response.Error = ErrorStrings.DATA_ACCESS_ERROR; return(response); } } }
public async Task ValidateUser([FromBody] UserAccountDTO user) { var dto = await _userService.GetUserByLogin(user.Login); await Response.WriteAsync(JsonConvert.SerializeObject(dto, new JsonSerializerSettings { Formatting = Formatting.Indented })); }
public async Task DeleteNotifications([FromBody] UserAccountDTO user) { await _notifService.DeleteNotificationsAsync(user.Id); await Response.WriteAsync(JsonConvert.SerializeObject(null, new JsonSerializerSettings { Formatting = Formatting.Indented })); }
public async Task ChangePass([FromBody] UserAccountDTO user) { var dto = await _userService.ChangePass(user.Login, user.Password); await Response.WriteAsync(JsonConvert.SerializeObject(dto, new JsonSerializerSettings { Formatting = Formatting.Indented })); }
/// <summary> /// The method gets the updated account of user from PL and save it in DB /// </summary> /// <param name="element">The updated account</param> public void UpdateElement(UserAccountDTO element) { Mapper.Initialize(configuration => configuration.CreateMap <UserAccountDTO, UserAccount>()); var account = Mapper.Map <UserAccountDTO, UserAccount>(element); uow.UsersAccounts.Update(account); uow.SaveChanges(); }
public UserAccountDTO Create(UserAccountDTO oUserAccountDTO) { if (oUserAccountDTO != null) { oUserAccountRepo.CreateUserAccount(UserAccountAssembler.ToEntity(oUserAccountDTO)); return(oUserAccountDTO); } return(null); }
public UserAccountDTO Create(UserAccountDTO modelDTO) { if (modelDTO != null) { var userAccount = UserAccountAssembler.ToEntity(modelDTO); return(UserAccountAssembler.ToDTO(userAccountRepo.CreateUserAccount(userAccount))); } return(null); }
public async Task Register([FromBody] UserAccountDTO user) { clientURL = Request.Headers["origin"]; string requestUrl = Request.Scheme + "://" + Request.Host; var dto = await _userService.CreateUser(user.Email, user.Login, user.Password, requestUrl); await Response.WriteAsync(JsonConvert.SerializeObject(dto, new JsonSerializerSettings { Formatting = Formatting.Indented })); }
public UserAccountDTO Get(int id) { UserAccountDTO oUserAccountDTO = null; if (id > 0) { UserAccount oUserAccount = userAccountRepo.GetUserAccountByID(id); } return(oUserAccountDTO); }
public UserAccountDTO Get(int UserAccountID) { UserAccountDTO oUserAccountDTO = null; if (UserAccountID > 0) { UserAccount oUserAccount = oUserAccountRepo.GetUserAccountByID(UserAccountID); } return(oUserAccountDTO); }
public UserAccountDTO ToDTO(UserAccountEntity entity) { UserAccountDTO dto = new UserAccountDTO(); dto.CreateTime = entity.CreateTime; dto.Id = entity.Id; dto.Amount = entity.Amount; dto.BonusAmount = entity.BonusAmount; // dto.UID = entity.User.ShopUID; dto.UserId = entity.UserId; return(dto); }
public UserAccountDTO Update(UserAccountDTO modelDTO) { UserAccountDTO returnUserAccount = null; if (modelDTO != null && (modelDTO.UserAccountID > 0 || modelDTO.UserName != null)) { userAccountRepo.UpdateUserAccount(UserAccountAssembler.ToEntity(modelDTO)); returnUserAccount = modelDTO; } return(returnUserAccount); }
public async Task Login([FromBody] UserAccountDTO user) { var dto = await _userService.Authenticate(user.Login, user.Password); if (dto == null) { await Response.WriteAsync(JsonConvert.SerializeObject(dto, new JsonSerializerSettings { Formatting = Formatting.Indented })); } await Response.WriteAsync(await _userTokensService.CreateToken(dto)); }
public UserAccountDTO Update(UserAccountDTO oUserAccountDTO) { UserAccountDTO returnUserAccount = null; if (oUserAccountDTO != null && oUserAccountDTO.UserAccountID > 0) { oUserAccountRepo.UpdateUserAccount(UserAccountAssembler.ToEntity(oUserAccountDTO)); returnUserAccount = oUserAccountDTO; } return(returnUserAccount); }
public void DeleteUserAccount(UserAccountDTO userAccount) { using var connection = new SQLiteConnection(DatabaseAgent.ConnectionString); { connection.Open(); using var command = new SQLiteCommand(SqlStatements.DeleteUserAccount, connection); { command.Parameters.AddWithValue("$Id", userAccount.Id); command.Prepare(); command.ExecuteNonQuery(); } } }
public async Task SendCode([FromBody] UserAccountDTO user) { CodeDTO verificationCode = new CodeDTO() { Code = rand.Next(100000, 999999) }; string message = $"<h2>Your verification code: {verificationCode.Code}<h2>"; _emailService.SendEmailAsync(user.Email, "Verification code", message); await Response.WriteAsync(JsonConvert.SerializeObject(verificationCode, new JsonSerializerSettings { Formatting = Formatting.Indented })); }
private UserAccountDTO GetUserAccountDTO() { UserAccountDTO userAccountObj = new UserAccountDTO { AccountName = "Calvin", AccountBalance = 234500, AccountTypeId = 12, InterestRate = 2, Timestamp = BitConverter.GetBytes(1552474127), UserId = "9999" }; return(userAccountObj); }
public IActionResult Put(string id, [FromBody] UserAccountDTO accountDTO) { var account = _mapper.Map <UserAccount>(accountDTO); try { _userAccountService.Update(account, id); return(Ok()); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }
public ChangePassword ChangePassword(ChangePassword dataModel) { if (dataModel != null) { UserAccountDTO userAccountDTO = new UserAccountDTO(); userAccountDTO = UserDataModelAssembler.ToUserChnagePasswordDTO(dataModel); if (userAccountDTO != null) { userAccountDTO = AccountBL.Update(userAccountDTO); } } return(dataModel); }
private void CreateAdminFromExistingUser(ParkingMaster.DataAccess.UserContext context) { var userGateway = new UserGateway(context); Guid adminId = new Guid("C0651A73-D8A4-4FDB-A5B3-032E4F9442EA"); List <Claim> claimsList = new List <Claim>(); UserAccountDTO adminAccount = userGateway.GetUserByUserId(adminId).Data; claimsList.Add(new Claim("Action", "UsageDashboard")); claimsList.Add(new Claim("Action", "ViewLogs")); claimsList.Add(new Claim("User", adminAccount.Username)); adminAccount.RoleType = Roles.ADMINISTRATOR; userGateway.SetRole(adminAccount); userGateway.ResetUserClaims(adminId, claimsList); }
public IActionResult Create([FromBody] UserAccountDTO accountDTO) { var account = _mapper.Map <UserAccount>(accountDTO); try { // save _userAccountService.Create(account); return(Ok()); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
public static UserAccountDTO ToUserChnagePasswordDTO(ChangePassword datamodel) { UserAccountDTO model = new UserAccountDTO(); if (datamodel != null) { model.UserAccountID = datamodel.UserAccountID; model.UserID = datamodel.UserID; if (datamodel.UserAccountPassword != null) { model.Password = Encoding.ASCII.GetBytes(datamodel.UserAccountPassword); } model.UserName = datamodel.UserAccountUserName; } return(model); }
public static UserAccountDTO ToUserAccountDTO(UserDataModel datamodel) { UserAccountDTO model = new UserAccountDTO(); if (datamodel != null) { model.UserAccountID = datamodel.UserAccountID; model.insdt = datamodel.UserAccountinsdt; model.insuser = datamodel.UserAccountinsuser; model.IsActive = datamodel.UserAccountIsActive; model.IsDeleted = datamodel.UserAccountIsDeleted; model.Password = datamodel.UserAccountPassword; model.upddt = datamodel.UserAccountupddt; model.upduser = datamodel.UserAccountupduser; model.UserName = datamodel.UserAccountUserName; } return(model); }
/// <summary> /// Method finds a user by login /// </summary> /// <param name="login">The user's login</param> public UserAccountDTO GetByLogin(string login) { var requestedUser = uow.UsersAccounts.FindElement(user => user.Login == login).FirstOrDefault(); if (requestedUser == null) { return(null); } UserAccountDTO account = new UserAccountDTO { UserId = requestedUser.UserAccountId, Login = requestedUser.Login, HashOfPassword = requestedUser.HashOfPassword }; //Mapper.Initialize(configutation => configutation.CreateMap<UserAccount, UserAccountDTO>()); //return Mapper.Map<UserAccount, UserAccountDTO>(requestedUser); return(account); }
public async Task <IActionResult> LogIn([FromBody] UserAccountDTO userInfo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = await _context.UserAccounts.FindAsync(userInfo.Id); if (user == null) { return(NotFound("User id not found")); } else if (user.Password != userInfo.Password) { return(NotFound("Wrong password")); } return(Ok()); }
public UserDataModel CreateUser(UserDataModel userDataModel) { if (userDataModel != null) { UserDTO userDTO = new UserDTO(); UserAccountDTO userAccountDTO = new UserAccountDTO(); PhoneDTO oPhoneDTO = new PhoneDTO(); EmailDTO oEmailDTO = new EmailDTO(); AddressDTO oAddressDTO = new AddressDTO(); userDTO = UserDataModelAssembler.ToUserDTO(userDataModel); userAccountDTO = UserDataModelAssembler.ToUserAccountDTO(userDataModel); oPhoneDTO = UserDataModelAssembler.ToPhoneDTO(userDataModel); oEmailDTO = UserDataModelAssembler.ToEmailDTO(userDataModel); oAddressDTO = UserDataModelAssembler.ToAddressDTO(userDataModel); if (userDTO != null) { userDTO = usersBL.Create(userDTO); } if (userAccountDTO != null) { userAccountDTO = AccountBL.Create(userAccountDTO); } if (oPhoneDTO != null) { oPhoneDTO = oPhonesBL.Create(oPhoneDTO); } if (oEmailDTO != null) { oEmailsBL.Create(oEmailDTO); } if (oAddressDTO != null) { oAddressBL.Create(oAddressDTO); } } return(userDataModel); }
public UserDataModel Update(UserDataModel dataModel) { if (dataModel != null) { UserDTO userDTO = new UserDTO(); UserAccountDTO userAccountDTO = new UserAccountDTO(); PhoneDTO phoneDTO = new PhoneDTO(); EmailDTO emailDTO = new EmailDTO(); AddressDTO addressDTO = new AddressDTO(); userDTO = UserDataModelAssembler.ToUserDTO(dataModel); userAccountDTO = UserDataModelAssembler.ToUserAccountDTO(dataModel); phoneDTO = UserDataModelAssembler.ToPhoneDTO(dataModel); emailDTO = UserDataModelAssembler.ToEmailDTO(dataModel); addressDTO = UserDataModelAssembler.ToAddressDTO(dataModel); if (userDTO != null) { userDTO = usersBL.Update(userDTO); } if (userAccountDTO != null) { userAccountDTO = AccountBL.Update(userAccountDTO); } if (phoneDTO != null) { phoneDTO = phonesBL.Update(phoneDTO); } if (emailDTO != null) { EmailsBL.Update(emailDTO); } if (addressDTO != null) { AddressBL.Update(addressDTO); } } return(dataModel); }
public async Task <string> CreateToken(UserAccountDTO user) { var username = user.Login; var password = user.Password; var identity = await GetIdentity(username, password); if (identity == null) { return(""); } var now = DateTime.UtcNow; var jwt = new JwtSecurityToken( issuer: AuthOptions.ISSUER, audience: AuthOptions.AUDIENCE, notBefore: now, claims: identity.Claims, expires: now.Add(TimeSpan.FromMinutes(AuthOptions.LIFETIME)), signingCredentials: new SigningCredentials(AuthOptions.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256)); var encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwt); var response = new { access_token = encodedJwt, login = identity.Name, id = user.Id, email = user.Email, role = identity.Claims .Where(c => c.Type == ClaimTypes.Role) .Select(c => c.Value) }; string token = JsonConvert.SerializeObject(response, new JsonSerializerSettings { Formatting = Formatting.Indented }); return(token); }