public EntityResponse<User> Login(LoginRequest credentials) { var response = new EntityResponse<User> {EntityType = typeof (User).ToString()}; // set up domain context var ctx = new PrincipalContext(ContextType.Domain); if (ctx.ValidateCredentials(credentials.UserName, credentials.Password)) { var user = UserPrincipal.FindByIdentity(ctx, credentials.UserName); if (user != null) { var u = new User { Email = user.EmailAddress, DisplayName = user.DisplayName, UserName = credentials.UserName }; response.ResponseCode = ResponseCode.Success; response.Message = ResponseMessage.Success; response.Data = u; } else { SetResponseError(ref response); } } else SetResponseError(ref response); return response; }
public IAsyncResult BeginLogin(LoginRequest request, AsyncCallback callback, object state) { var controller = new AuthController(); var task = Task<EntityResponse<User>>.Factory.StartNew(r => controller.Login(request), state); return task.ContinueWith(r => callback(task)); }