public UserLogInService(
     IDataUnitOfWork data,
     IAuthenticationTokenService tokenService)
 {
     this.data         = data;
     this.tokenService = tokenService;
 }
Ejemplo n.º 2
0
 public AuthenticationService(IUnitOfWork unitOfWork, ICryptService cryptService,
                              IAuthenticationTokenService authenticationTokenService)
 {
     _unitOfWork   = unitOfWork;
     _cryptService = cryptService;
     _authenticationTokenService = authenticationTokenService;
 }
Ejemplo n.º 3
0
 public ConservativeStrategy(
     IAuthenticationTokenService authService,
     IUserCredentialSource credentialSource,
     string authTokenType)
     : base(authService, credentialSource, authTokenType)
 {
 }
Ejemplo n.º 4
0
 public SettingsBasedStrategy(
     IAuthenticationTokenService authService,
     IUserCredentialSource credentialSource,
     string authTokenType)
     : base(authService, credentialSource, authTokenType)
 {
 }
 public JabbRAuthenticationCallbackProvider(IAuthenticationTokenService authenticationTokenService,
                                            IMembershipService membershipService,
                                            IJabbrRepository repository)
 {
     _authenticationTokenService = authenticationTokenService;
     _membershipService = membershipService;
     _repository = repository;
 }
Ejemplo n.º 6
0
 public static Response CompleteLogin(this NancyModule module,
                                      IAuthenticationTokenService authenticationTokenService,
                                      ChatUser user)
 {
     var response = module.Response.AsRedirect("~/");
     response.AddAuthenticationCookie(authenticationTokenService, user);
     return response;
 }
 public JabbRAuthenticationCallbackProvider(IAuthenticationTokenService authenticationTokenService,
                                            IMembershipService membershipService,
                                            IJabbrRepository repository)
 {
     _authenticationTokenService = authenticationTokenService;
     _membershipService          = membershipService;
     _repository = repository;
 }
Ejemplo n.º 8
0
 protected AuthenticationStrategy(
     IAuthenticationTokenService authService,
     IUserCredentialSource credentialSource,
     string authTokenType)
 {
     m_authService      = authService;
     m_credentialSource = credentialSource;
     m_authTokenType    = authTokenType;
 }
Ejemplo n.º 9
0
        private static void AddAuthenticationCookie(this Response response,
                                                   IAuthenticationTokenService authenticationTokenService,
                                                   ChatUser user)
        {
            string userToken = authenticationTokenService.GetAuthenticationToken(user);
            var cookie = new NancyCookie(Constants.UserTokenCookie, userToken, httpOnly: true)
            {
                Expires = DateTime.Now + TimeSpan.FromDays(30)
            };

            response.AddCookie(cookie);
        }
Ejemplo n.º 10
0
        private static void AddAuthenticationCookie(this Response response,
                                                    IAuthenticationTokenService authenticationTokenService,
                                                    ChatUser user)
        {
            string userToken = authenticationTokenService.GetAuthenticationToken(user);
            var    cookie    = new NancyCookie(Constants.UserTokenCookie, userToken, httpOnly: true)
            {
                Expires = DateTime.Now + TimeSpan.FromDays(30)
            };

            response.AddCookie(cookie);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Sets the Auth Cookie and Redirects
        /// </summary>
        /// <param name="module"></param>
        /// <param name="authenticationTokenService"></param>
        /// <param name="user">the User to be logged in</param>
        /// <param name="redirectUrl">optional URL to redirect to, default is querystring returnUrl, if present, otherwise the root</param>
        /// <returns></returns>
        public static Response CompleteLogin(this NancyModule module,
                                             IAuthenticationTokenService authenticationTokenService,
                                             ChatUser user,
                                             string redirectUrl = null)
        {
            string returnUrl = redirectUrl ?? module.Request.Query.returnUrl;
            if (String.IsNullOrWhiteSpace(returnUrl))
            {
                returnUrl = "~/";
            }

            var response = module.Response.AsRedirect(returnUrl);
            response.AddAuthenticationCookie(authenticationTokenService, user);
            return response;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Sets the Auth Cookie and Redirects
        /// </summary>
        /// <param name="module"></param>
        /// <param name="authenticationTokenService"></param>
        /// <param name="user">the User to be logged in</param>
        /// <param name="redirectUrl">optional URL to redirect to, default is querystring returnUrl, if present, otherwise the root</param>
        /// <returns></returns>
        public static Response CompleteLogin(this NancyModule module,
                                             IAuthenticationTokenService authenticationTokenService,
                                             ChatUser user,
                                             string redirectUrl = null)
        {
            string returnUrl = redirectUrl ?? module.Request.Query.returnUrl;

            if (String.IsNullOrWhiteSpace(returnUrl))
            {
                returnUrl = "~/";
            }

            var response = module.Response.AsRedirect(returnUrl);

            response.AddAuthenticationCookie(authenticationTokenService, user);
            return(response);
        }
Ejemplo n.º 13
0
        public HomeModule(IAuthenticationTokenService authService)
        {
            Get["/"] = _ =>
            {
                if (Context.CurrentUser != null)
                {
                    var viewModel = new SettingsViewModel
                    {
                        GoogleAnalytics = ConfigurationManager.AppSettings["googleAnalytics"],
                        Sha = ConfigurationManager.AppSettings["googleAnalytics"],
                        Branch = ConfigurationManager.AppSettings["releaseBranch"],
                        Time = ConfigurationManager.AppSettings["releaseTime"]
                    };

                    return View["index", viewModel];
                }

                return Response.AsRedirect("~/account/login");
            };
        }
Ejemplo n.º 14
0
 public RundownElementAccess(IAuthenticationTokenService authenticationService, TenantName tenant)
     : base(tenant, authenticationService)
 {
 }
 public _ControllerBase(IAuthenticationTokenService authenticationTokenService)
 {
     _authenticationTokenService = authenticationTokenService;
 }
Ejemplo n.º 16
0
 internal AuthenticationServiceStub(IAuthenticationTokenService service)
 {
     m_service = service;
 }
Ejemplo n.º 17
0
 public AuthorizationHandler(AppFunc next, IAuthenticationTokenService authenticationTokenService)
 {
     _next = next;
     _authenticationTokenService = authenticationTokenService;
 }
Ejemplo n.º 18
0
 public AuthorizationHandler(AppFunc next, IAuthenticationTokenService authenticationTokenService)
 {
     _next = next;
     _authenticationTokenService = authenticationTokenService;
 }
Ejemplo n.º 19
0
        public AccountModule(IApplicationSettings applicationSettings,
                             IAuthenticationTokenService authenticationTokenService,
                             IMembershipService membershipService,
                             IJabbrRepository repository,
                             IAuthenticationService authService,
                             IChatNotificationService notificationService)
            : base("/account")
        {
            Get["/"] = _ =>
            {
                if (Context.CurrentUser == null)
                {
                    return(HttpStatusCode.Forbidden);
                }

                ChatUser user = repository.GetUserById(Context.CurrentUser.UserName);

                return(GetProfileView(authService, user));
            };

            Get["/login"] = _ =>
            {
                if (Context.CurrentUser != null)
                {
                    return(Response.AsRedirect("~/"));
                }

                return(View["login", GetLoginViewModel(applicationSettings, repository, authService)]);
            };

            Post["/login"] = param =>
            {
                if (Context.CurrentUser != null)
                {
                    return(Response.AsRedirect("~/"));
                }

                string username = Request.Form.username;
                string password = Request.Form.password;

                if (String.IsNullOrEmpty(username))
                {
                    this.AddValidationError("username", "Name is required");
                }

                if (String.IsNullOrEmpty(password))
                {
                    this.AddValidationError("password", "Password is required");
                }

                try
                {
                    if (ModelValidationResult.IsValid)
                    {
                        ChatUser user = membershipService.AuthenticateUser(username, password);
                        return(this.CompleteLogin(authenticationTokenService, user));
                    }
                    else
                    {
                        return(View["login", GetLoginViewModel(applicationSettings, repository, authService)]);
                    }
                }
                catch
                {
                    this.AddValidationError("_FORM", "Login failed. Check your username/password.");
                    return(View["login", GetLoginViewModel(applicationSettings, repository, authService)]);
                }
            };

            Post["/logout"] = _ =>
            {
                if (Context.CurrentUser == null)
                {
                    return(HttpStatusCode.Forbidden);
                }

                var response = Response.AsJson(new { success = true });

                response.AddCookie(new NancyCookie(Constants.UserTokenCookie, null)
                {
                    Expires = DateTime.Now.AddDays(-1)
                });

                return(response);
            };

            Get["/register"] = _ =>
            {
                if (Context.CurrentUser != null)
                {
                    return(Response.AsRedirect("~/"));
                }

                return(View["register"]);
            };

            Post["/create"] = _ =>
            {
                if (Context.CurrentUser != null)
                {
                    return(Response.AsRedirect("~/"));
                }

                string username        = Request.Form.username;
                string email           = Request.Form.email;
                string password        = Request.Form.password;
                string confirmPassword = Request.Form.confirmPassword;

                if (String.IsNullOrEmpty(username))
                {
                    this.AddValidationError("username", "Name is required");
                }

                if (String.IsNullOrEmpty(email))
                {
                    this.AddValidationError("email", "Email is required");
                }

                ValidatePassword(password, confirmPassword);

                try
                {
                    if (ModelValidationResult.IsValid)
                    {
                        ChatUser user = membershipService.AddUser(username, email, password);
                        return(this.CompleteLogin(authenticationTokenService, user));
                    }
                }
                catch (Exception ex)
                {
                    this.AddValidationError("_FORM", ex.Message);
                }

                return(View["register"]);
            };

            Post["/unlink"] = param =>
            {
                if (Context.CurrentUser == null)
                {
                    return(HttpStatusCode.Forbidden);
                }

                string   provider = Request.Form.provider;
                ChatUser user     = repository.GetUserById(Context.CurrentUser.UserName);

                if (user.Identities.Count == 1 && !user.HasUserNameAndPasswordCredentials())
                {
                    this.AddAlertMessage("error", "You cannot unlink this account because you would lose your ability to login.");
                    return(Response.AsRedirect("~/account/#identityProviders"));
                }

                var identity = user.Identities.FirstOrDefault(i => i.ProviderName == provider);

                if (identity != null)
                {
                    repository.Remove(identity);

                    this.AddAlertMessage("success", String.Format("Successfully unlinked {0} account.", provider));
                    return(Response.AsRedirect("~/account/#identityProviders"));
                }

                return(HttpStatusCode.BadRequest);
            };

            Post["/newpassword"] = _ =>
            {
                if (Context.CurrentUser == null)
                {
                    return(HttpStatusCode.Forbidden);
                }

                string password        = Request.Form.password;
                string confirmPassword = Request.Form.confirmPassword;

                ValidatePassword(password, confirmPassword);

                ChatUser user = repository.GetUserById(Context.CurrentUser.UserName);

                try
                {
                    if (ModelValidationResult.IsValid)
                    {
                        membershipService.SetUserPassword(user, password);
                        repository.CommitChanges();
                    }
                }
                catch (Exception ex)
                {
                    this.AddValidationError("_FORM", ex.Message);
                }

                if (ModelValidationResult.IsValid)
                {
                    this.AddAlertMessage("success", "Successfully added a password.");
                    return(Response.AsRedirect("~/account/#changePassword"));
                }

                return(GetProfileView(authService, user));
            };

            Post["/changepassword"] = _ =>
            {
                if (Context.CurrentUser == null)
                {
                    return(HttpStatusCode.Forbidden);
                }

                string oldPassword     = Request.Form.oldPassword;
                string password        = Request.Form.password;
                string confirmPassword = Request.Form.confirmPassword;

                if (String.IsNullOrEmpty(oldPassword))
                {
                    this.AddValidationError("oldPassword", "Old password is required");
                }

                ValidatePassword(password, confirmPassword);

                ChatUser user = repository.GetUserById(Context.CurrentUser.UserName);

                try
                {
                    if (ModelValidationResult.IsValid)
                    {
                        membershipService.ChangeUserPassword(user, oldPassword, password);
                        repository.CommitChanges();
                    }
                }
                catch (Exception ex)
                {
                    this.AddValidationError("_FORM", ex.Message);
                }

                if (ModelValidationResult.IsValid)
                {
                    this.AddAlertMessage("success", "Successfully changed your password.");
                    return(Response.AsRedirect("~/account/#changePassword"));
                }

                return(GetProfileView(authService, user));
            };

            Post["/changeusername"] = _ =>
            {
                if (Context.CurrentUser == null)
                {
                    return(HttpStatusCode.Forbidden);
                }

                string username        = Request.Form.username;
                string confirmUsername = Request.Form.confirmUsername;

                ValidateUsername(username, confirmUsername);

                ChatUser user        = repository.GetUserById(Context.CurrentUser.UserName);
                string   oldUsername = user.Name;

                try
                {
                    if (ModelValidationResult.IsValid)
                    {
                        membershipService.ChangeUserName(user, username);
                        repository.CommitChanges();
                    }
                }
                catch (Exception ex)
                {
                    this.AddValidationError("_FORM", ex.Message);
                }

                if (ModelValidationResult.IsValid)
                {
                    notificationService.OnUserNameChanged(user, oldUsername, username);

                    this.AddAlertMessage("success", "Successfully changed your username.");
                    return(Response.AsRedirect("~/account/#changeUsername"));
                }

                return(GetProfileView(authService, user));
            };
        }
Ejemplo n.º 20
0
 public TestAccess(IAuthenticationTokenService authenticationService) : base(authenticationService)
 {
 }
 public MoovieController(IMoovieService moovieService, IAuthenticationTokenService authenticationTokenService)
     : base(authenticationTokenService)
 {
     _moovieService = moovieService;
 }
 internal AuthenticationServiceStub( IAuthenticationTokenService service )
 {
     m_service = service;
 }
Ejemplo n.º 23
0
 public AuthenticateController(IMembershipService membershipService, IAuthenticationTokenService tokenService)
 {
     _membershipService = membershipService;
     _tokenService = tokenService;
 }
Ejemplo n.º 24
0
 public AuthenticateController(IMembershipService membershipService, IAuthenticationTokenService tokenService)
 {
     _membershipService = membershipService;
     _tokenService      = tokenService;
 }
 public UserRegistrationService(IDataUnitOfWork data,
                                IAuthenticationTokenService authenticationTokenService)
 {
     this.data = data;
     this.authenticationTokenService = authenticationTokenService;
 }
Ejemplo n.º 26
0
        public AccountModule(IApplicationSettings applicationSettings,
                             IAuthenticationTokenService authenticationTokenService,
                             IMembershipService membershipService,
                             IJabbrRepository repository,
                             IAuthenticationService authService,
                             IChatNotificationService notificationService)
            : base("/account")
        {
            Get["/"] = _ =>
            {
                if (Context.CurrentUser == null)
                {
                    return HttpStatusCode.Forbidden;
                }

                ChatUser user = repository.GetUserById(Context.CurrentUser.UserName);

                return GetProfileView(authService, user);
            };

            Get["/login"] = _ =>
            {
                if (Context.CurrentUser != null)
                {
                    return Response.AsRedirect("~/");
                }

                return View["login", GetLoginViewModel(applicationSettings, repository, authService)];
            };

            Post["/login"] = param =>
            {
                if (Context.CurrentUser != null)
                {
                    return Response.AsRedirect("~/");
                }

                string username = Request.Form.username;
                string password = Request.Form.password;

                if (String.IsNullOrEmpty(username))
                {
                    this.AddValidationError("username", "Name is required");
                }

                if (String.IsNullOrEmpty(password))
                {
                    this.AddValidationError("password", "Password is required");
                }

                try
                {
                    if (ModelValidationResult.IsValid)
                    {
                        ChatUser user = membershipService.AuthenticateUser(username, password);
                        return this.CompleteLogin(authenticationTokenService, user);
                    }
                    else
                    {
                        return View["login", GetLoginViewModel(applicationSettings, repository, authService)];
                    }
                }
                catch
                {
                    this.AddValidationError("_FORM", "Login failed. Check your username/password.");
                    return View["login", GetLoginViewModel(applicationSettings, repository, authService)];
                }
            };

            Post["/logout"] = _ =>
            {
                if (Context.CurrentUser == null)
                {
                    return HttpStatusCode.Forbidden;
                }

                var response = Response.AsJson(new { success = true });

                response.AddCookie(new NancyCookie(Constants.UserTokenCookie, null)
                {
                    Expires = DateTime.Now.AddDays(-1)
                });

                return response;
            };

            Get["/register"] = _ =>
            {
                if (Context.CurrentUser != null)
                {
                    return Response.AsRedirect("~/");
                }

                return View["register"];
            };

            Post["/create"] = _ =>
            {
                if (Context.CurrentUser != null)
                {
                    return Response.AsRedirect("~/");
                }

                string username = Request.Form.username;
                string email = Request.Form.email;
                string password = Request.Form.password;
                string confirmPassword = Request.Form.confirmPassword;

                if (String.IsNullOrEmpty(username))
                {
                    this.AddValidationError("username", "Name is required");
                }

                if (String.IsNullOrEmpty(email))
                {
                    this.AddValidationError("email", "Email is required");
                }

                ValidatePassword(password, confirmPassword);

                try
                {
                    if (ModelValidationResult.IsValid)
                    {
                        ChatUser user = membershipService.AddUser(username, email, password);
                        return this.CompleteLogin(authenticationTokenService, user);
                    }
                }
                catch (Exception ex)
                {
                    this.AddValidationError("_FORM", ex.Message);
                }

                return View["register"];
            };

            Post["/unlink"] = param =>
            {
                if (Context.CurrentUser == null)
                {
                    return HttpStatusCode.Forbidden;
                }

                string provider = Request.Form.provider;
                ChatUser user = repository.GetUserById(Context.CurrentUser.UserName);

                if (user.Identities.Count == 1 && !user.HasUserNameAndPasswordCredentials())
                {
                    this.AddAlertMessage("error", "You cannot unlink this account because you would lose your ability to login.");
                    return Response.AsRedirect("~/account/#identityProviders");
                }

                var identity = user.Identities.FirstOrDefault(i => i.ProviderName == provider);

                if (identity != null)
                {
                    repository.Remove(identity);

                    this.AddAlertMessage("success", String.Format("Successfully unlinked {0} account.", provider));
                    return Response.AsRedirect("~/account/#identityProviders");
                }

                return HttpStatusCode.BadRequest;
            };

            Post["/newpassword"] = _ =>
            {
                if (Context.CurrentUser == null)
                {
                    return HttpStatusCode.Forbidden;
                }

                string password = Request.Form.password;
                string confirmPassword = Request.Form.confirmPassword;

                ValidatePassword(password, confirmPassword);

                ChatUser user = repository.GetUserById(Context.CurrentUser.UserName);

                try
                {
                    if (ModelValidationResult.IsValid)
                    {
                        membershipService.SetUserPassword(user, password);
                        repository.CommitChanges();
                    }
                }
                catch (Exception ex)
                {
                    this.AddValidationError("_FORM", ex.Message);
                }

                if (ModelValidationResult.IsValid)
                {
                    this.AddAlertMessage("success", "Successfully added a password.");
                    return Response.AsRedirect("~/account/#changePassword");
                }

                return GetProfileView(authService, user);
            };

            Post["/changepassword"] = _ =>
            {
                if (Context.CurrentUser == null)
                {
                    return HttpStatusCode.Forbidden;
                }

                string oldPassword = Request.Form.oldPassword;
                string password = Request.Form.password;
                string confirmPassword = Request.Form.confirmPassword;

                if (String.IsNullOrEmpty(oldPassword))
                {
                    this.AddValidationError("oldPassword", "Old password is required");
                }

                ValidatePassword(password, confirmPassword);

                ChatUser user = repository.GetUserById(Context.CurrentUser.UserName);

                try
                {
                    if (ModelValidationResult.IsValid)
                    {
                        membershipService.ChangeUserPassword(user, oldPassword, password);
                        repository.CommitChanges();
                    }
                }
                catch (Exception ex)
                {
                    this.AddValidationError("_FORM", ex.Message);
                }

                if (ModelValidationResult.IsValid)
                {
                    this.AddAlertMessage("success", "Successfully changed your password.");
                    return Response.AsRedirect("~/account/#changePassword");
                }

                return GetProfileView(authService, user);
            };

            Post["/changeusername"] = _ =>
            {
                if (Context.CurrentUser == null)
                {
                    return HttpStatusCode.Forbidden;
                }

                string username = Request.Form.username;
                string confirmUsername = Request.Form.confirmUsername;

                ValidateUsername(username, confirmUsername);

                ChatUser user = repository.GetUserById(Context.CurrentUser.UserName);
                string oldUsername = user.Name;

                try
                {
                    if (ModelValidationResult.IsValid)
                    {
                        membershipService.ChangeUserName(user, username);
                        repository.CommitChanges();
                    }
                }
                catch (Exception ex)
                {
                    this.AddValidationError("_FORM", ex.Message);
                }

                if (ModelValidationResult.IsValid)
                {
                    notificationService.OnUserNameChanged(user, oldUsername, username);

                    this.AddAlertMessage("success", "Successfully changed your username.");
                    return Response.AsRedirect("~/account/#changeUsername");
                }

                return GetProfileView(authService, user);
            };
        }
Ejemplo n.º 27
0
 public RundownCompositesAccess(IAuthenticationTokenService authenticationService, TenantName tenant)
     : base(tenant, authenticationService)
 {
 }