Beispiel #1
1
        private MainFrame myViewFrame; //View

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Guest user controller constructor
        /// </summary>
        /// <param name="ts">View frame</param>
        public UserController(MainFrame ts)
        {
            myViewFrame = ts;
            myUser = new User(-1);
        }
Beispiel #2
0
 /// <summary>
 /// Logout user , set guest view
 /// </summary>
 /// <returns>True</returns>
 public Boolean logout()
 {
     myUserLogin = null;
     myUser = new User(-1);
     myViewFrame.setGuestViewOptions();
     return true;
 }
Beispiel #3
0
        /// <summary>
        /// Register user
        /// </summary>
        /// <param name="regval">Dictionary containing Fieldname-Value</param>
        /// <returns>Successful/Unsuccessful registration</returns>
        public static bool registerUser(Dictionary<String, String> regval)
        {
            if (!isAlreadyregistered(regval["email"]))
            {
                String comm = "Insert into Users(Username,EncPass,Email,Birthdate,UserTypeId";
                string utype = getUsertype(regval["type"]);
                string encpass = MD5Hash(regval["pass1"]);

                if (utype == "4")//free
                {
                    comm += ") values (";
                    comm += "'" + regval["username"] + "',";
                    comm += "'" + encpass + "',";
                    comm+="'"+regval["email"]+"',";
                    comm+="'"+regval["birthdate"]+"',";
                    comm+=""+utype+")";

                }

                else{//Publisher/Pro

                    comm += ",Firstname,Lastname,Cardnumber,Validationnumber,ExpirationDate,Credit) values (";
                    comm += "'" + regval["username"] + "',";
                    comm += "'" + encpass + "',";
                    comm += "'" + regval["email"] + "',";
                    comm += "'" + regval["birthdate"] + "',";
                    comm += "" + utype + ",";
                    comm += "'" + regval["firstname"] + "',";
                    comm += "'" + regval["lastname"] + "',";
                    comm += "'" + regval["cardnum"] + "',";
                    comm += "'" + regval["valnum"] + "',";
                    comm += "'" + regval["expdate"] + "',";

                  //  MessageBox.Show(regval["initcredit"].TrimEnd('$'));

                    comm += "" + regval["initcredit"].TrimEnd('$') + ")";

                }

                User u=new User(-1);
                string s = u.ExecuteNonQuery(comm);
                if (s != "OK")
                {
                    MessageBox.Show("Registration Error:"+s);
                    return false;
                }
                else {
                    MessageBox.Show("Registration Succsesful!!");
                    return true;
                }

            }
            else
            {
                MessageBox.Show("User with this e-mail already registered!!");
                return false;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Login user by username and password and set view by user type
        /// </summary>
        /// <param name="uname">Username</param>
        /// <param name="passw">Password</param>
        /// <returns>Succesful/Unsuccesful(true/false)</returns>
        public Boolean login(String uname, String passw)
        {
            myUserLogin = new Login(uname, passw);
            myUser = new User(myUserLogin.userId);
            if (myUserLogin.loggedIn)
                myViewFrame.setViewByUserType(myUserLogin.group);

            return myUserLogin.loggedIn;
        }
Beispiel #5
0
        /// <summary>
        /// Checking if is user already registered with given e-mail address
        /// </summary>
        /// <param name="email"></param>
        /// <returns>True/False</returns>
        private static bool isAlreadyregistered(string email)
        {
            string comm = "SELECT * FROM Users WHERE email = '" + email + "'";

            User u = new User(-1);
            String s = "";
            SqlDataReader reader = u.ExecuteReader(comm, ref s);

            bool isRegistered = false;

            while (reader.Read())
            {
                isRegistered = true;

            }
            reader.Close();

            return isRegistered;
        }
Beispiel #6
0
        /// <summary>
        /// Get user group id
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        private static string getUsertype(string p)
        {
            string comm = "SELECT UTypeID FROM UserTypes WHERE Usertypename = '" + p + "'";

            User u = new User(-1);
            String s = "";
            SqlDataReader reader = u.ExecuteReader(comm, ref s);

            while (reader.Read())
            {
                s = reader["UTypeID"].ToString();

            }
            reader.Close();

            return s;
        }
Beispiel #7
0
        /// <summary>
        /// Checking information correctness and registering user 
        /// </summary>
        /// <param name="userinfo"></param>
        internal void registerUser(Dictionary<string, string> userinfo)
        {
            if (userinfo["pass1"] == userinfo["pass2"] && userinfo["pass1"].Length > 5)
            {
                if (userinfo["username"].Length == 0 || userinfo["email"].Length == 0)
                {
                    MessageBox.Show("Please fill the required fields");
                }
                else
                {

                    if (User.registerUser(userinfo))
                    {
                        myViewFrame.setUserandPass(userinfo["username"], userinfo["pass1"]);
                        myUser = new User(myUserLogin.userId);
                    }
                }

            }
            else
                MessageBox.Show("Passwords didn't match/Short password!(Min 6 char)");
        }