protected override bool CheckAccessCore(OperationContext operationContext) { //Get the current pipeline user context var identity = operationContext.ServiceSecurityContext.PrimaryIdentity; var userFound = uCtrl.GetUser(identity.Name); if (operationContext.EndpointDispatcher.ContractName == "IMetadataExchange") { string[] userRolesFound = { "Guest" }; var principal = new GenericPrincipal(operationContext.ServiceSecurityContext.PrimaryIdentity, userRolesFound); operationContext.ServiceSecurityContext.AuthorizationContext.Properties["Principal"] = principal; return(true); } else if (userFound != null) { string[] userRolesFound = userFound.Roles.Select(x => x.ToString()).ToArray(); //Assign roles to the Principal property for runtime to match with PrincipalPermissionAttributes decorated on the service operation. var principal = new GenericPrincipal(operationContext.ServiceSecurityContext.PrimaryIdentity, userRolesFound); //assign principal to auth context with the users roles operationContext.ServiceSecurityContext.AuthorizationContext.Properties["Principal"] = principal; //return true if all goes well return(true); } else { Console.WriteLine("Service: User unknown!"); throw new FaultException("User not found"); } }
public bool CreateLogin(string email, string password, string firstname, string lastname, string address, int zipcode, long phonenumber) { bool lykkes = false; email = email.ToString().Trim().ToLower(); password = password.Trim(); firstname = firstname.Trim(); lastname = lastname.Trim(); address = address.Trim(); if (email.Length >= 6 && password.Length >= 4 && firstname.Length >= 2 && lastname.Length >= 2 && address.Length >= 4 && zipcode > 999 && phonenumber > 0) { if (email.Contains("@") && email.Contains(".")) { User exists = uCtrl.GetUser(email); if (exists == null) { Customer c = new Customer(); c.Email = email; c.Password = password; c.FirstName = firstname; c.LastName = lastname; c.Address = address; c.City = cityCtrl.Get(zipcode); c.Role = "User"; c.CPR = 0000000000; c.Confirmed = false; if (uCtrl.CreateUser(c)) { lykkes = true; } } else if (exists != null) { lykkes = false; } } } return(lykkes); }
public User GetUser(int id) { try { return(uCtrl.GetUser(id)); } catch (Exception) { throw; } }
public override void Validate(string email, string password) { email = email.ToLower(); var foundUser = uCtrl.GetUser(email); if (foundUser != null && foundUser.Email == email && foundUser.Password == password) { Console.WriteLine("Service: " + foundUser.Email + " connected..."); //email pw are valid } else { Console.WriteLine("Service: login failed for " + email + " (wrong username or password)"); throw new FaultException <Exception>(new Exception("Invalid Login..."), "Invalid Credentials"); } }
/// <summary> /// Calls the method GetUser from the user controller /// </summary> /// <param name="id">the id of the user</param> /// <returns>returns the method with a user from the specified id /// from user controller</returns> public User GetUser(int id) { return(userCtrl.GetUser(id)); }