public string AddUser(string userName, string password) { System.Diagnostics.Debug.WriteLine("AddUser cu valorile : username="******" password="******""; bool isUserName = false; using (var dbContext = new UserTokenDbContext()) { isUserName = new DatabaseUsers(dbContext).IsUserName(userName); if (isUserName) { return("Numele de utilizator este deja folosit !"); } else { string hashedPass = Hash.Get(password, salt); User newUsr = new User(); newUsr.Username = userName; newUsr.Password = hashedPass; newUsr.Salt = salt; var userAdaugat = new DatabaseUsers(dbContext).AddNewUser(newUsr); if (userAdaugat) { message = "Am adaugat utilizatorul " + userName; } } } return(message); }
public User GetUserDetails(string UserId) { using (var dbContext = new UserTokenDbContext()) { System.Diagnostics.Debug.WriteLine("GetUserDetails cu id-ul: " + UserId); var userDetails = new DatabaseUsers(dbContext).GetUserDetails(UserId);; return(userDetails); } }
public List <User> GetAllUsers() { using (var dbContext = new UserTokenDbContext()) { System.Diagnostics.Debug.WriteLine("GetAllUsers"); var userList = new DatabaseUsers(dbContext).GetUsers(); return(userList); } }
public bool DeleteUser(string UserId) { using (var dbContext = new UserTokenDbContext()) { System.Diagnostics.Debug.WriteLine("DeleteUser cu id-ul : " + UserId); var userDeleted = new DatabaseUsers(dbContext).DeleteUser(UserId); return(userDeleted); } }
public UserDataContract Authenticate(Credentials creds) { if (creds == null && WebOperationContext.Current != null) { creds = new BasicAuth(WebOperationContext.Current.IncomingRequest.Headers["Authorization"]).Creds; } using (var dbContext = new UserTokenDbContext()) { return(new DatabaseTokenBuilder(dbContext).Build(creds)); } }
public bool UpdateUser(string Id, string Username, string Password, string Role, string Salt) { using (var dbContext = new UserTokenDbContext()) { User contact = new User(); contact.Id = Convert.ToInt32(Id); contact.Username = Username; contact.Password = Password; contact.Role = Role; contact.Salt = Salt; System.Diagnostics.Debug.WriteLine("UpdateUser"); var userUpdated = new DatabaseUsers(dbContext).UpdateUser(contact); return(userUpdated); } }
private static void ValidateBasicAuthentication() { var authorization = WebOperationContext.Current.IncomingRequest.Headers["Authorization"]; if (string.IsNullOrWhiteSpace(authorization)) { using (var dbContext = new UserTokenDbContext()) { var basicAuth = new BasicAuth(authorization); if (null == new DatabaseCredentialsValidator(dbContext).IsValid(basicAuth.Creds)) { throw new AuthenticationException(); } } } }
private static void ValidateToken(string token) { System.Diagnostics.Debug.WriteLine("Validate token cu valoarea : " + token); if (token != "signup") //daca token include signup fac exceptie la regula validarii pentru noii utilizatori { using (var dbContext = new UserTokenDbContext()) { ITokenValidator validator = new DatabaseTokenValidator(dbContext); if (!validator.IsValid(token)) { throw new WebFaultException(HttpStatusCode.Forbidden); } // Add User ids to the header so the service has them if needed WebOperationContext.Current.IncomingRequest.Headers.Add("User", validator.Token.User.Username); WebOperationContext.Current.IncomingRequest.Headers.Add("UserId", validator.Token.User.Id.ToString()); WebOperationContext.Current.OutgoingResponse.Headers.Add("User", validator.Token.User.Username.ToString()); WebOperationContext.Current.OutgoingResponse.Headers.Add("UserId", validator.Token.User.Id.ToString()); WebOperationContext.Current.OutgoingResponse.Headers.Add("Role", validator.Token.User.Role.ToString()); } } }
public DatabaseCredentialsValidator(UserTokenDbContext dbContext) { _DbContext = dbContext; }
public DatabaseUsers(UserTokenDbContext dbContext) { _DbContext = dbContext; }
public DatabaseTokenBuilder(UserTokenDbContext dbContext) { _DbContext = dbContext; }
public DatabaseTokenValidator(UserTokenDbContext dbContext) { _DbContext = dbContext; }