Beispiel #1
0
        /// <summary>
        /// Handles the Click event of the bAccept control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void bAccept_Click(object sender, EventArgs e)
        {
            if (!Util.StringSanitizer.TestStringSanitizationWithoutBlank(this.tBGroupName.Text))
            {
                MessageBox.Show("Name must be formed of chars and numbers");
            }
            else
            {
                session = ((Forms.Main) this.Owner).Session;
                Guid newToken = Guid.Empty;

                try
                {
                    if (!groupController.CreateNewGroup(out newToken, session.User.Id, session.CurrentToken, this.tBGroupName.Text, session.User.Id))
                    {
                        MessageBox.Show("Group couldn't be created");
                    }
                    else
                    {
                        session.CurrentToken = newToken;
                        MessageBox.Show("Group created");
                        this.Close();
                    }
                }
                catch
                {
                    MessageBox.Show("Error creating group");
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Handles the Click event of the bAccept control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void bAccept_Click(object sender, EventArgs e)
        {
            session = ((Forms.Main) this.Owner).Session;
            Guid newToken = Guid.Empty;

            string tagName = this.tBTag.Text;

            Model.Tag.Tag tag   = tagController.GetTagByName(tagName);
            long          tagID = 1;

            if (tag == null)
            {
                tag      = new Model.Tag.Tag();
                tag.Id   = tagID;
                tag.Name = tagName;
                tagController.AddTag(out newToken, out tagID, session.User.Id, session.CurrentToken, tag);
                session.CurrentToken = newToken;
            }

            tagController.AddUserSubscription(out newToken, session.User.Id, session.CurrentToken, session.User.Id, tagID);

            session.CurrentToken = newToken;

            this.Close();
        }
Beispiel #3
0
        /// <summary>
        /// Gets the new token.
        /// </summary>
        /// <param name="userEmail">The user email.</param>
        /// <param name="password">The password.</param>
        /// <param name="session">The session.</param>
        /// <returns></returns>
        public bool GetNewToken(string userEmail, string password, Model.Session.Session session)
        {
            try
            {
                session.CurrentToken = loginService.GetNewToken(userEmail, password);
                return(true);
            }

            catch
            {
                session.CurrentToken = Guid.Empty;
                return(false);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Handles the Click event of the bRegister control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void bRegister_Click(object sender, EventArgs e)
        {
            session = ((Forms.Main) this.Owner).Session;
            Controller.UsersController userController = new Controller.UsersController();

            bool registered = userController.RegisterNewUser(this.tBNick.Text, this.tBNewMail.Text, this.tBNewPassword.Text, 1);

            if (registered)
            {
                MessageBox.Show("User succesfully registered, now you can login");
            }
            else
            {
                MessageBox.Show("Error registering new user");
            }
        }
Beispiel #5
0
        /// <summary>
        /// Handles the Click event of the bLogin control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void bLogin_Click(object sender, EventArgs e)
        {
            session = ((Forms.Main) this.Owner).Session;
            bool login = loginController.LoginWithPassword(tBEmail.Text, tBPassword.Text, session);

            if (login)
            {
                MessageBox.Show("Login succesful");
                ((Main)(this.Owner)).LoadUser(session.User);
                this.Close();
            }
            else
            {
                MessageBox.Show("Error trying to login");
            }
        }
Beispiel #6
0
        /// <summary>
        /// Logins the with key.
        /// </summary>
        /// <param name="userEmail">The user email.</param>
        /// <param name="session">The session.</param>
        /// <returns></returns>
        public bool LoginWithKey(string userEmail, Model.Session.Session session)
        {
            try
            {
                Guid newSecurityToken          = Guid.Empty;
                LoginServices.User serviceUser = loginService.Login(out newSecurityToken, userEmail, session.CurrentToken);
                session.User         = this.convertToModelUser(serviceUser);
                session.Logged       = true;
                session.CurrentToken = newSecurityToken;

                return(true);
            }
            catch
            {
                session.User         = null;
                session.Logged       = false;
                session.CurrentToken = Guid.Empty;

                return(false);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Logins the with password.
        /// </summary>
        /// <param name="userEmail">The user email.</param>
        /// <param name="password">The password.</param>
        /// <param name="session">The session.</param>
        /// <returns></returns>
        public bool LoginWithPassword(string userEmail, string password, Model.Session.Session session)
        {
            try
            {
                bool isOK = true;

                isOK = this.GetNewToken(userEmail, password, session);
                if (isOK)
                {
                    isOK = this.LoginWithKey(userEmail, session);
                }
                if (isOK)
                {
                    session.Logged = true;
                    return(true);
                }
                return(isOK);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #8
0
 /// <summary>
 /// Disconnects the specified session.
 /// </summary>
 /// <param name="session">The session.</param>
 public void Disconnect(Model.Session.Session session)
 {
     session.Logged       = false;
     session.User         = new Model.User.User();
     session.CurrentToken = Guid.Empty;
 }
Beispiel #9
0
 /// <summary>
 /// Handles the Click event of the bLogin control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 private void bLogin_Click(object sender, EventArgs e)
 {
     Forms.Login           loginForm = new XareuWFClient.Forms.Login();
     Model.Session.Session session   = ((Forms.Main) this.ParentForm).Session;
     loginForm.ShowDialog(this.ParentForm);
 }