public async Task <IActionResult> Register(LoginViewModel loginViewModel)
        {
            try
            {
                UserCollection userCollection = new UserCollection();
                if (userCollection.DoesUserExist(loginViewModel.UserName))
                {
                    ModelState.Clear();
                    ModelState.AddModelError("Username", "Username is already used");
                    return(View(loginViewModel));
                }

                if (loginViewModel.Password.Length < 8)
                {
                    ModelState.Clear();
                    ModelState.AddModelError("Password", "Password needs to be at least 8 characters long");
                    return(View(loginViewModel));
                }
                else
                {
                    User user = new User(loginViewModel.UserName, loginViewModel.Password);
                    userCollection.AddUser(ConvertUser(user));

                    return(LocalRedirect("/Account/Login"));
                }
            }
            catch
            {
                TempData["Error"] = true;
                return(View(loginViewModel));
            }
        }
        /// <summary>
        /// Get all users of the given SharePoint.
        /// </summary>
        /// <param name="clientContext">clientContext of SharePoint</param>
        /// <returns>all users of given SharePoint</returns>
        /// <exception cref="ElementsMigrationException">If the SiteUsers could not be fetched</exception>
        private UserCollection GetAllUser(ClientContext clientContext)
        {
            Web web = clientContext.Web;

            GroupCollection groups = web.SiteGroups;

            try
            {
                clientContext.Load(groups);
                clientContext.ExecuteQuery();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception during fetching the Groups.", e);
                Logger.AddMessage("Exception during fetching the Group. Error = " + e.Message);
                throw new ElementsMigrationException("Exception during fetching the Groups.", e);
            }

            UserCollection userCollection = null;

            foreach (var group in groups)
            {
                try
                {
                    clientContext.Load(group.Users);
                    clientContext.ExecuteQuery();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception during fetching the Users.", e);
                    Logger.AddMessage("Exception during fetching the users. Error = " + e.Message);
                    throw new ElementsMigrationException("Exception during fetching the Users.", e);
                }

                if (group.Users == null || group.Users.Count == 0)
                {
                    continue;
                }

                if (userCollection == null)
                {
                    userCollection = group.Users;
                }
                else
                {
                    foreach (var user in group.Users)
                    {
                        userCollection.AddUser(user);
                    }
                }
            }

            return(userCollection);
        }
 protected void btnLogin_Click1(object sender, EventArgs e)
 {
     if (txtPassword.Text.Equals(txtPasswordConfirm.Text))
     {
         try
         {
             UserCollection.AddUser(new User("0", txtUser.Text, txtPassword.Text));
         }
         catch (Exception ex)
         {
             lblError.Text = ex.ToString();
         }
     }
     else
     {
         lblError.Text = "Password doesn't Match";
     }
 }
        bool wantToRegister = false;//allow user to create a client account and check if all data are valid
        private void Register_Click(object sender, RoutedEventArgs e)
        {
            LogIn.Visibility = Visibility.Collapsed;

            if (!wantToRegister)
            {
                ConfirmPassword.Visibility = Visibility.Visible;
                wantToRegister             = true;
                tBValidation.Text          = "Enter your data..";
                tBValidation.Foreground    = new SolidColorBrush(Colors.LightGreen);
            }
            else if (password.Text == tBConfirmPassword.Text)
            {
                if (!InterfaceManager.ValidPassword(password.Text))
                {
                    tBValidation.Foreground = new SolidColorBrush(Colors.Red);
                    tBValidation.Text       = "PassWord have to contain 8 characteres, upper and lower case";
                }
                else if (!uCollect.IsUser(userName.Text))
                {
                    User temp = new User(AutorisationLevel.Client, userName.Text, tBConfirmPassword.Text);
                    uCollect.AddUser(temp);
                    tBValidation.Text          = "Your account have been created.. you can login..";
                    tBValidation.Foreground    = new SolidColorBrush(Colors.LightGreen);
                    ConfirmPassword.Visibility = Visibility.Collapsed;
                    ClearUI();
                    LogIn.Visibility = Visibility.Visible;
                    wantToRegister   = false;
                }
                else
                {
                    tBValidation.Foreground = new SolidColorBrush(Colors.Red);
                    tBValidation.Text       = "An account already Exist with this username";
                }
            }
            else
            {
                tBValidation.Foreground = new SolidColorBrush(Colors.Red);
                tBValidation.Text       = "Your passwords are different";
            }
        }
        //Create a user
        private void createUser_Click(object sender, RoutedEventArgs e)
        {
            if (!InterfaceManager.ValidPassword(tBPasswordUser.Text))
            {
                PasswordValidation.Foreground = new SolidColorBrush(Colors.Red);
                PasswordValidation.Text       = "PassWord have to contain 8 characteres, upper and lower case";
                return;
            }
            string password = tBPasswordUser.Text;

            if (_uCollect.IsUser(tBNameUser.Text))
            {
                PasswordValidation.Foreground = new SolidColorBrush(Colors.Red);
                PasswordValidation.Text       = "Username already exist. Chose another one...";
                return;
            }
            string            name = tBNameUser.Text;
            AutorisationLevel autoLevel;

            if (rBEmployee.IsChecked == true)
            {
                autoLevel = AutorisationLevel.Employee;
            }
            else if (rBManager.IsChecked == true)
            {
                autoLevel = AutorisationLevel.Manager;
            }
            else
            {
                PasswordValidation.Foreground = new SolidColorBrush(Colors.Red);
                PasswordValidation.Text       = "Choose an autorisation Level";
                return;
            }

            User tmp = new User(autoLevel, name, password);

            _uCollect.AddUser(tmp);
            PasswordValidation.Foreground = new SolidColorBrush(Colors.Green);
            PasswordValidation.Text       = "User Created";
            ClearUIData();
        }
Beispiel #6
0
        public void TryLogin(DbAccount user, EAClient client)
        {
            //is someone else already logged in as this user?
            var oldUser = Users.GetUserByName(user.Username);

            if (oldUser != null)
            {
                oldUser.Connection.Close(); //should remove the old user.
                Thread.Sleep(500);
            }

            var personas = new string[4];

            for (int i = 0; i < user.Personas.Count; i++)
            {
                personas[i] = user.Personas[i];
            }

            //make a user object from DB user
            var user2 = new User()
            {
                Connection = client,
                ID         = user.ID,
                Personas   = personas,
                Username   = user.Username,
                IP         = client.IP
            };

            Users.AddUser(user2);
            client.User = user2;

            client.SendMessage(new AuthOut()
            {
                TOS      = user.ID.ToString(),
                NAME     = user.Username,
                PERSONAS = string.Join(',', user.Personas)
            });

            Rooms.SendRooms(user2);
        }