public async Task <ActionResult> Manage(ManageUserViewModel model)
        {
            string userId        = User.Identity.GetUserId();
            string localUserName = await Logins.GetProviderKey(User.Identity.GetUserId(), IdentityConfig.LocalLoginProvider);

            bool hasLocalLogin = localUserName != null;

            ViewBag.HasLocalPassword = hasLocalLogin;
            ViewBag.ReturnUrl        = Url.Action("Manage");
            if (hasLocalLogin)
            {
                if (ModelState.IsValid)
                {
                    bool changePasswordSucceeded = await ChangePassword(localUserName, model.OldPassword, model.NewPassword);

                    if (changePasswordSucceeded)
                    {
                        return(RedirectToAction("Manage", new { Message = ManageMessageId.ChangePasswordSuccess }));
                    }
                    else
                    {
                        ModelState.AddModelError(String.Empty, "The current password is incorrect or the new password is invalid.");
                    }
                }
            }
            else
            {
                // User does not have a local password so remove any validation errors caused by a missing OldPassword field
                ModelState state = ModelState["OldPassword"];
                if (state != null)
                {
                    state.Errors.Clear();
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        // Create the local login info and link the local account to the user
                        localUserName = User.Identity.GetUserName();
                        if (await Secrets.Create(new UserSecret(localUserName, model.NewPassword)) &&
                            await Logins.Add(new UserLogin(userId, IdentityConfig.LocalLoginProvider, localUserName)))
                        {
                            return(RedirectToAction("Manage", new { Message = ManageMessageId.SetPasswordSuccess }));
                        }
                        else
                        {
                            ModelState.AddModelError(String.Empty, "Failed to set password");
                        }
                    }
                    catch (Exception e)
                    {
                        ModelState.AddModelError(String.Empty, e);
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // Create a profile, password, and link the local login before signing in the user
                    User user = new User(model.UserName);
                    if (await Users.Create(user) &&
                        await Secrets.Create(new UserSecret(model.UserName, model.Password)) &&
                        await Logins.Add(new UserLogin(user.Id, IdentityConfig.LocalLoginProvider, model.UserName)))
                    {
                        await SignIn(user.Id, isPersistent : false);

                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError(String.Empty, "Failed to create login for: " + model.UserName);
                    }
                }
                catch (DbEntityValidationException e)
                {
                    ModelState.AddModelError("", e.EntityValidationErrors.First().ValidationErrors.First().ErrorMessage);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 3
0
 public virtual void AddLogin(Login login)
 {
     if (login == null)
     {
         throw new ArgumentNullException("login");
     }
     login.User = this;
     Logins.Add(login);
 }
Exemplo n.º 4
0
        public virtual void AddLogin(MongoUserLogin userLogin)
        {
            if (userLogin == null)
            {
                throw new ArgumentNullException(nameof(userLogin));
            }

            Logins.Add(userLogin);
        }
Exemplo n.º 5
0
 public LoginForm()
 {
     Logins.Add(new Login("723901", "Dr.Onyeka"));
     Logins.Add(new Login("449123", "Tyler"));
     Logins.Add(new Login("234192", "Robert"));
     Logins.Add(new Login("143232", "Jareth"));
     Logins.Add(new Login("592120", "Morgan"));
     Logins.Add(new Login("712387", "Jordan"));
     InitializeComponent();
 }
 public virtual void AssignLogin(string loginProvider, string providerKey)
 {
     if (!HasLogin(loginProvider, providerKey))
     {
         Logins.Add(new IdentityUserLogin
         {
             LoginProvider = loginProvider,
             ProviderKey   = providerKey
         });
     }
 }
Exemplo n.º 7
0
        public virtual bool AddLogin(UserLoginInfo info)
        {
            if (HasLogin(info))
            {
                return(false);
            }

            Logins.Add(info);

            return(true);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Opens a async. connection
        /// </summary>
        /// <param name="dns">DNS String</param>
        /// <param name="port">Port as Integer</param>
        /// <param name="login">Login as LoginData</param>
        /// <see cref="LoginData"/>
        public void openConnection(string dns, int port, LoginData login)
        {
            IPHostEntry ipHostInfo     = Dns.Resolve(dns);
            IPAddress   ipAdress       = ipHostInfo.AddressList[0];
            IPEndPoint  remoteEndPoint = new IPEndPoint(ipAdress, port);
            Socket      socket         = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            Sockets.Add(socket);
            Logins.Add(login);
            Connect(remoteEndPoint, socket);
        }
        public void AddLogin(UserLoginInfo loginInfo)
        {
            var existingLoginInfo = Logins.SingleOrDefault(t => t.LoginProvider == loginInfo.LoginProvider);

            if (existingLoginInfo == null)
            {
                Logins.Add(loginInfo);
            }
            else
            {
                existingLoginInfo.ProviderDisplayName = loginInfo.ProviderDisplayName;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Adds a user login to the user.
        /// </summary>
        /// <param name="userLoginInfo">The <see cref="UserLoginInfo"/> you want to add.</param>
        /// <returns>True if the addition was successful.</returns>
        public virtual bool AddLogin(UserLoginInfo userLoginInfo)
        {
            if (userLoginInfo == null)
            {
                throw new ArgumentNullException(nameof(userLoginInfo));
            }
            if (HasLogin(userLoginInfo))
            {
                return(false);
            }

            Logins.Add(new UserLoginInfo(userLoginInfo.LoginProvider, userLoginInfo.ProviderKey, userLoginInfo.ProviderDisplayName));
            return(true);
        }
Exemplo n.º 11
0
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model,
                                                                   string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var id = await HttpContext.GetExternalIdentity();

                if (id == null)
                {
                    return(View("ExternalLoginFailure"));
                }
                try
                {
                    // Create a local user and sign in
                    var user = new User(model.UserName);
                    if (await Users.Create(user) &&
                        await Logins.Add(new UserLogin(user.Id,
                                                       model.LoginProvider,
                                                       id.FindFirstValue(ClaimTypes.NameIdentifier))))
                    {
                        await SignIn(user.Id,
                                     id.Claims,
                                     isPersistent : false);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        return(View("ExternalLoginFailure"));
                    }
                }
                catch (DbEntityValidationException e)
                {
                    ModelState.AddModelError("",
                                             e.EntityValidationErrors.First()
                                             .ValidationErrors.First()
                                             .ErrorMessage);
                }
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
        public async Task <ActionResult> ExternalLoginCallback(string loginProvider, string returnUrl)
        {
            // Get the information about the user from the external login provider
            ClaimsIdentity id = await HttpContext.GetExternalIdentity();

            if (id == null)
            {
                return(View("ExternalLoginFailure"));
            }

            // Make sure the external identity is from the loginProvider we expect
            Claim providerKeyClaim = id.FindFirst(ClaimTypes.NameIdentifier);

            if (providerKeyClaim == null || providerKeyClaim.Issuer != loginProvider)
            {
                return(View("ExternalLoginFailure"));
            }

            // Succeeded so we should be able to lookup the local user name and sign them in
            string providerKey = providerKeyClaim.Value;
            string userId      = await Logins.GetUserId(loginProvider, providerKey);

            if (!String.IsNullOrEmpty(userId))
            {
                await SignIn(userId, id.Claims, isPersistent : false);
            }
            else
            {
                // No local user for this account
                if (User.Identity.IsAuthenticated)
                {
                    // If the current user is logged in, just add the new account
                    await Logins.Add(new UserLogin(User.Identity.GetUserId(), loginProvider, providerKey));
                }
                else
                {
                    ViewBag.ReturnUrl = returnUrl;
                    return(View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel {
                        UserName = id.Name, LoginProvider = loginProvider
                    }));
                }
            }

            return(RedirectToLocal(returnUrl));
        }
Exemplo n.º 13
0
        public static void CreateLogin(string User, string Pass, string Perm)
        {
            List <Login> Logins;
            Login        newLogin = new Login()
            {
                UserName = User, Password = Pass, Permissions = Perm
            };

            if (File.Exists(FilePath))
            {
                Logins = GetLogins();
            }
            else
            {
                Logins = new List <Login>();
            }

            Logins.Add(newLogin);
            writeLogins(Logins);
        }
Exemplo n.º 14
0
 public void AssignLogins(IList logins)
 {
     if (logins == null)
     {
         return;
     }
     foreach (var login in new XPCollection(Session, typeof(XpoDxUserLogin), CriteriaOperator.Parse("[User!Key] == ?", Id), null))
     {
         Logins.Remove(login as XpoDxUserLogin);
     }
     foreach (var l in logins)
     {
         IDxUserLogin <string> login = l as IDxUserLogin <string>;
         if (l != null)
         {
             Logins.Add(new XpoDxUserLogin(Session)
             {
                 User          = this,
                 LoginProvider = login.LoginProvider,
                 ProviderKey   = login.ProviderKey
             });
         }
     }
 }
Exemplo n.º 15
0
 public virtual void AddLogin(UserLoginInfo login)
 {
     Logins.Add(new IdentityUserLogin(login));
 }
Exemplo n.º 16
0
 internal void AddLogin(UserLoginInfo login)
 {
     Logins.Add(new UserLogin(login));
 }
Exemplo n.º 17
0
        public virtual void AddLogin([NotNull] UserLoginInfo login)
        {
            Check.NotNull(login, nameof(login));

            Logins.Add(new IdentityUserLogin(Id, login, TenantId));
        }
Exemplo n.º 18
0
 public void AddLogin(UserLoginInfo login)
 {
     Logins.Add(login);
 }
Exemplo n.º 19
0
 public void AddLogin(LoginID login)
 {
     Logins.Add(login);
 }
Exemplo n.º 20
0
 internal void AddLogin(UserLoginInfo login)
 {
     Logins.Add(new UserLoginInfo(login.LoginProvider, login.ProviderKey, login.ProviderDisplayName));
 }
 public void AppendSocialLogin(UserLoginInfo info)
 {
     Logins.Add(info);
     //Changes.Add("UserLoginInfo-"+info.LoginProvider);
     PropertyChanges.Enqueue(new UserPropertyChange("AppendSocialLogin", info));
 }