public virtual void SetUp()
        {
            _getCurrentUserHandler       = _getCurrentUserHandler.Fake();
            _loginHandler                = _loginHandler.Fake();
            _logoutHandler               = _logoutHandler.Fake();
            _nancySecurityContextFactory = _nancySecurityContextFactory.Fake();
            _sut          = new UsersModule(_getCurrentUserHandler, _loginHandler, _logoutHandler, _nancySecurityContextFactory);
            _bootstrapper = new ApiBootstrapper(with => {
                with.Module(_sut);
                with.RootPathProvider(new InvoiceGenRootPathProvider());
            });
            _browser = new Browser(_bootstrapper, to => to.Accept(new MediaRange("application/json")));

            _authenticatedUser = new User {
                GivenName = "John",
                LastName  = "Doe",
                Login     = new Login {
                    Value = "JDoe"
                },
                Password = new Password {
                    Value       = "P@$$w0rd",
                    IsEncrypted = false
                }
            };
        }
Example #2
0
        public UsersModule(
            IHandler <GetCurrentUserRequest, User> getCurrentUserHandler,
            IHandler <LoginRequest, bool> loginHandler,
            IHandler <LogoutRequest, bool> logoutHandler,
            INancySecurityContextFactory nancySecurityContextFactory)
        {
            if (getCurrentUserHandler == null)
            {
                throw new ArgumentNullException("getCurrentUserHandler");
            }
            if (loginHandler == null)
            {
                throw new ArgumentNullException("loginHandler");
            }
            if (logoutHandler == null)
            {
                throw new ArgumentNullException("logoutHandler");
            }
            if (nancySecurityContextFactory == null)
            {
                throw new ArgumentNullException("nancySecurityContextFactory");
            }

            Get["api/user", true] = async(parameters, cancellationToken) => {
                this.RequiresAuthentication();
                return(await getCurrentUserHandler.Handle(this.Bind(() =>
                                                                    new GetCurrentUserRequest {
                    SecurityContext = nancySecurityContextFactory.Create(Context)
                })));
            };

            Post["api/user/login", true] = async(parameters, cancellationToken) => await loginHandler.Handle(this.Bind(() => {
                var loginRequest = this.Bind <LoginRequest>();
                return(new LoginRequest {
                    SecurityContext = nancySecurityContextFactory.Create(Context),
                    Login = loginRequest?.Login,
                    Password = loginRequest?.Password
                });
            }));

            Post["api/user/logout", true] = async(parameters, cancellationToken) => {
                this.RequiresAuthentication();
                return(await logoutHandler.Handle(this.Bind(() =>
                                                            new LogoutRequest {
                    SecurityContext = nancySecurityContextFactory.Create(Context)
                })));
            };
        }
        public virtual void SetUp()
        {
            _getCurrentUserHandler = _getCurrentUserHandler.Fake();
              _loginHandler = _loginHandler.Fake();
              _logoutHandler = _logoutHandler.Fake();
              _nancySecurityContextFactory = _nancySecurityContextFactory.Fake();
              _sut = new UsersModule(_getCurrentUserHandler, _loginHandler, _logoutHandler, _nancySecurityContextFactory);
              _bootstrapper = new ApiBootstrapper(with => {
            with.Module(_sut);
            with.RootPathProvider(new InvoiceGenRootPathProvider());
              });
              _browser = new Browser(_bootstrapper, to => to.Accept(new MediaRange("application/json")));

              _authenticatedUser = new User {
            GivenName = "John",
            LastName = "Doe",
            Login = new Login {Value = "JDoe"},
            Password = new Password {
              Value = "P@$$w0rd",
              IsEncrypted = false
            }
              };
        }
Example #4
0
        public virtual void SetUp()
        {
            _getCurrentUserHandler           = _getCurrentUserHandler.Fake();
            _loginLocalUserHandler           = _loginLocalUserHandler.Fake();
            _loginGooglePlusUserHandler      = _loginGooglePlusUserHandler.Fake();
            _activateGooglePlusUserHandler   = _activateGooglePlusUserHandler.Fake();
            _disconnectGooglePlusUserHandler = _disconnectGooglePlusUserHandler.Fake();
            _logoutHandler = _logoutHandler.Fake();
            _nancySecurityContextFactory = _nancySecurityContextFactory.Fake();
            _sut = new UsersModule(
                _getCurrentUserHandler,
                _loginLocalUserHandler,
                _loginGooglePlusUserHandler,
                _activateGooglePlusUserHandler,
                _disconnectGooglePlusUserHandler,
                _logoutHandler,
                _nancySecurityContextFactory);
            _bootstrapper = new AppBootstrapper(with => {
                with.Module(_sut);
                with.RootPathProvider(new VoterRootPathProvider());
            });
            _browser = new Browser(_bootstrapper, to => to.Accept(new MediaRange("application/json")));

            _authenticatedUser = new User {
                UniqueId  = Guid.NewGuid(),
                FirstName = "John",
                LastName  = "Doe",
                Login     = new Login {
                    Value = "JDoe"
                },
                Password = new Password {
                    Value       = "P@$$w0rd",
                    IsEncrypted = false
                }
            };
        }
Example #5
0
        public UsersModule(
      IHandler<GetCurrentUserRequest, User> getCurrentUserHandler,
      IHandler<LoginRequest, bool> loginHandler,
      IHandler<LogoutRequest, bool> logoutHandler,
      INancySecurityContextFactory nancySecurityContextFactory)
        {
            if (getCurrentUserHandler == null) throw new ArgumentNullException("getCurrentUserHandler");
              if (loginHandler == null) throw new ArgumentNullException("loginHandler");
              if (logoutHandler == null) throw new ArgumentNullException("logoutHandler");
              if (nancySecurityContextFactory == null) throw new ArgumentNullException("nancySecurityContextFactory");

              Get["api/user", true] = async (parameters, cancellationToken) => {
            this.RequiresAuthentication();
            return await getCurrentUserHandler.Handle(this.Bind(() =>
              new GetCurrentUserRequest {
            SecurityContext = nancySecurityContextFactory.Create(Context)
              }));
              };

              Post["api/user/login", true] = async (parameters, cancellationToken) => await loginHandler.Handle(this.Bind(() => {
            var loginRequest = this.Bind<LoginRequest>();
            return new LoginRequest {
              SecurityContext = nancySecurityContextFactory.Create(Context),
              Login = loginRequest?.Login,
              Password = loginRequest?.Password
            };
              }));

              Post["api/user/logout", true] = async (parameters, cancellationToken) => {
            this.RequiresAuthentication();
            return await logoutHandler.Handle(this.Bind(() =>
              new LogoutRequest {
            SecurityContext = nancySecurityContextFactory.Create(Context)
              }));
              };
        }
Example #6
0
        public UsersModule(
            IHandler <GetCurrentUserRequest, User> getCurrentUserHandler,
            IHandler <LoginLocalUserRequest, bool> loginLocalUserHandler,
            IHandler <LoginGooglePlusUserRequest, bool> loginGooglePlusUserHandler,
            IHandler <ActivateGooglePlusUserRequest, bool> activateGooglePlusUserHandler,
            IHandler <DisconnectGooglePlusUserRequest, bool> disconnectGooglePlusUserHandler,
            IHandler <LogoutRequest, bool> logoutHandler,
            INancySecurityContextFactory nancySecurityContextFactory)
        {
            if (getCurrentUserHandler == null)
            {
                throw new ArgumentNullException(nameof(getCurrentUserHandler));
            }
            if (loginLocalUserHandler == null)
            {
                throw new ArgumentNullException(nameof(loginLocalUserHandler));
            }
            if (loginGooglePlusUserHandler == null)
            {
                throw new ArgumentNullException(nameof(loginGooglePlusUserHandler));
            }
            if (activateGooglePlusUserHandler == null)
            {
                throw new ArgumentNullException(nameof(activateGooglePlusUserHandler));
            }
            if (disconnectGooglePlusUserHandler == null)
            {
                throw new ArgumentNullException(nameof(disconnectGooglePlusUserHandler));
            }
            if (logoutHandler == null)
            {
                throw new ArgumentNullException(nameof(logoutHandler));
            }
            if (nancySecurityContextFactory == null)
            {
                throw new ArgumentNullException(nameof(nancySecurityContextFactory));
            }

            Get["api/user", true] = async(parameters, cancellationToken) => {
                this.RequiresAuthentication();
                return(await getCurrentUserHandler.Handle(this.Bind(() =>
                                                                    new GetCurrentUserRequest {
                    SecurityContext = nancySecurityContextFactory.Create(Context)
                })));
            };

            Post["api/user/login/local", true] = async(parameters, cancellationToken) => await loginLocalUserHandler.Handle(this.Bind(() => {
                var loginRequest = this.Bind <LoginLocalUserRequest>();
                return(new LoginLocalUserRequest {
                    SecurityContext = nancySecurityContextFactory.Create(Context),
                    Login = loginRequest?.Login,
                    Password = loginRequest?.Password
                });
            }));

            Post["api/user/login/googleplus", true] = async(parameters, cancellationToken) =>
                                                      await loginGooglePlusUserHandler.Handle(this.Bind(() => new LoginGooglePlusUserRequest {
                SecurityContext = nancySecurityContextFactory.Create(Context),
                Code = Context.Request.Body.AsString()
            }));

            Post["api/user/activate/googleplus", true] = async(parameters, cancellationToken) =>
                                                         await activateGooglePlusUserHandler.Handle(this.Bind(() => new ActivateGooglePlusUserRequest {
                SecurityContext = nancySecurityContextFactory.Create(Context),
                AccessToken = Context.Request.Body.AsString()
            }));

            Post["api/user/disconnect/googleplus", true] = async(parameters, cancellationToken) => {
                this.RequiresAuthentication();
                return(await disconnectGooglePlusUserHandler.Handle(this.Bind(() => new DisconnectGooglePlusUserRequest {
                    SecurityContext = nancySecurityContextFactory.Create(Context)
                })));
            };

            Post["api/user/logout", true] = async(parameters, cancellationToken) => {
                this.RequiresAuthentication();
                return(await logoutHandler.Handle(this.Bind(() =>
                                                            new LogoutRequest {
                    SecurityContext = nancySecurityContextFactory.Create(Context)
                })));
            };
        }