Esempio n. 1
0
        private void forgotPasswordBtn_Click(object sender, RoutedEventArgs e)
        {
            SignWindow signWindow = Helper.GetAncestorOfType <SignWindow>(this);

            if (signWindow != null)
            {
                signWindow.ShowForgotPassword();
            }
        }
Esempio n. 2
0
        private void btnSignUp_Click(object sender, RoutedEventArgs e)
        {
            SignWindow signWindow = Helper.GetAncestorOfType <SignWindow>(this);

            if (signWindow != null)
            {
                signWindow.ShowSignUp();
            }
        }
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            SignWindow signWindow = Helper.GetAncestorOfType <SignWindow>(this);

            if (signWindow != null)
            {
                parentWindow = signWindow;
            }


            proPicImg.Source = new BitmapImage(new Uri(@"/Assets/user_icon.png", UriKind.RelativeOrAbsolute));
            parentWindow.proPicImgPopUp.Source = "/Assets/user_icon.png";
        }
        private void sendEmailBtn_Click(object sender, RoutedEventArgs e)
        {
            // check if username is correct
            string email;
            User   user = DB.UserLogIn(tbUsername.Text);

            if (user == null)
            {
                SystemSounds.Exclamation.Play();
                MessageBox.Show("There is no user with that username! Try again.");
            }
            else if (string.IsNullOrWhiteSpace(user.Email))
            {
                SystemSounds.Exclamation.Play();
                MessageBox.Show("That username doesn't have an email. Contact support to get your account back.");
            }
            else
            {
                // generate temporary password
                string tempPwd = RandomString(6);

                // send email
                string title   = "Your temporary password - Deniso's Auctions";
                string msgBody = $"Hello {tbUsername.Text},\nThis is your temporary password which you will be able to use to access your account ONLY ONCE and will expire in 24 hours.\nTEMPORARY PASSWORD: {tempPwd}\n\nYou should change your password as soon as you access your account.";
                Helper.SendEmail(user.Email, title, msgBody);


                // register to database ResetTickets table
                DateTime expireDate = DateTime.Now.AddDays(1); // email expire date

                DB.SaveResetTicket(user.Id, tempPwd, expireDate);

                // go back to LogInControl
                MessageBox.Show("Email sent! Check your inbox.");

                SignWindow signWindow = Helper.GetAncestorOfType <SignWindow>(this);
                if (signWindow != null)
                {
                    signWindow.ShowLogIn();
                }
            }
        }
Esempio n. 5
0
        private void btnLogIn_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(tbUsername.Text) || string.IsNullOrWhiteSpace(pbPassword.Password))
            {
                MessageBox.Show("Some fields are empty");
                return;
            }
            string username = tbUsername.Text.Trim();
            string password = pbPassword.Password.Trim();

            User user = DB.UserLogIn(username, password);

            if (user != null)
            {
                Session.LoggedUser = user;
                SignWindow signWindow = Helper.GetAncestorOfType <SignWindow>(this);
                if (signWindow != null)
                {
                    signWindow.EnterApp(user.ProPicPath);
                }
            }
            else
            {
                //// does user exist? if so, he might have used a temp token
                //int userId = DB.GetUserId(username);
                //if(userId != -1)
                //{
                //    // check if he has a token available
                //    int ticketId = DB.TryGetToken(password, userId);
                //    if(ticketId > 0)
                //    {
                //        // set token as "Used" in table
                //        DB.TicketWasUsed(ticketId);

                //        // log user in
                //        user = DB.GetUser(userId);
                //        if(user != null)
                //        {
                //            Session.LoggedUser = user;
                //            SignWindow signWindow = Helper.GetAncestorOfType<SignWindow>(this);
                //            if (signWindow != null)
                //            {
                //                signWindow.EnterApp(user.ProPicPath);
                //            }
                //        }
                //    }
                //    else if(ticketId == 0)
                //    {
                //        MessageBox.Show("You tried to use a temporary password that has already been used");
                //    }
                //    else if(ticketId == -1)
                //    {
                //        MessageBox.Show("You tried to use a temporary password that has expired");
                //    }
                //    else
                //    {
                //        MessageBox.Show("Wrong password");
                //    }
                //}
                //else
                //{
                //    MessageBox.Show("That username doesn't exist");
                //}


                // does username exist?
                int id = DB.GetUserId(tbUsername.Text);
                if (id != -1)
                {
                    if (DB.GetToken(pbPassword.Password, id))
                    {
                        MessageBox.Show("Token used!");
                        DB.SetTokenToUsed(pbPassword.Password);

                        Session.LoggedUser = DB.UserLogIn(tbUsername.Text);
                        SignWindow signWindow = Helper.GetAncestorOfType <SignWindow>(this);
                        if (signWindow != null)
                        {
                            signWindow.EnterApp(Session.LoggedUser.ProPicPath);
                            return;
                        }
                    }
                }
                MessageBox.Show("Username or password wrong");
            }
        }