Beispiel #1
0
        /// <summary>
        /// Login do utilizador
        /// </summary>
        /// <param name="username">Username</param>
        /// <param name="password">Password</param>
        /// <returns>Token se login com sucesso, -1 se o user não existe, -2 se já esta loged in</returns>
        public static int LoginUser(string username, string password)
        {
            DataBaseManager db = new DataBaseManager();

            int uid = db.UserID(username, password);

            if (uid != -1)
            {
                if (!IsLoggedIn(uid))
                {
                    int token = rand.Next(1000, 9999);
                    if (AddToken(token, uid))
                    {
                        return(token);
                    }
                    else
                    {
                        return(-3);
                    }
                }
                else
                {
                    return(-2);
                }
            }
            else
            {
                return(-1);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Cria um pedido de registo
        /// </summary>
        /// <param name="usrnm"></param>
        /// <param name="psswd"></param>
        /// <returns></returns>
        public static int RegistrationRequest(string usrnm, string psswd)
        {
            DataBaseManager db = new DataBaseManager();

            if (db.UserID(usrnm) == -1 && !db.RegRequestExists(usrnm, psswd))
            {
                db.AddRegistrationRequest(usrnm, psswd);
                return(1);
            }
            else
            {
                return(-1);
            }
        }