示例#1
0
        /// <summary>
        /// Change a user's email.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <param name="newEmail">The new email address.</param>
        /// <param name="role">The role, DJ or mobile.</param>
        /// <returns>The outcome of the operation.</returns>
        public Response ChangeEmail(int ID, string role, string newEmail)
        {
            ExpResponse r = new ExpResponse();
            if (!role.Equals("DJ") && !role.Equals("Mobile"))
            {
                r.setErMsgStk(true, "Bad Role Given", Environment.StackTrace);
                return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);
            }

            // Validate the email address.
            try
            {
                var address = new System.Net.Mail.MailAddress(newEmail);
            }
            catch
            {
                r.setErMsg(true, Messages.ERR_BAD_EMAIL);
                return r;
            }

            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                r = db.OpenConnection();
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);

                if (role == "DJ")
                    r = db.DJSetEmail(ID, newEmail);
                else
                    r = db.MobileSetEmail(ID, newEmail);

                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);

                return r;
            }
        }
示例#2
0
        /// <summary>
        /// Starts the password reset process for users who forgot their passwords.
        /// </summary>
        /// <param name="email">The email address of the user.</param>
        /// <param name="key">Out parameter for the unique key this user will temporarily be associated with.</param>
        /// <param name="role">The role: DJ or Mobile</param>
        /// <returns>The outcome of the operation.</returns>
        public Response StartPasswordReset(string email, string username, bool isDJ, string websiteAddress)
        {
            ExpResponse r = new ExpResponse();
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                r = db.OpenConnection();
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);

                int ID;
                if (isDJ)
                    r = db.DJValidateUsernameEmail(username, email, out ID);
                else
                    r = db.MobileValidateUsernameEmail(username, email, out ID);

                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);

                if(ID == -1)
                {
                    r.setErMsg(true, Messages.MSG_EMAIL_NOT_FOUND);
                    return r;
                }

                string random = Common.CreateSalt(32);
                Regex rgx = new Regex("[^a-zA-Z0-9 -]");
                random = rgx.Replace(random, "x");
                int uniqueIsNegOne = 0;

                while (uniqueIsNegOne != -1)
                {
                    if (isDJ)
                        r = db.DJGetPasswordResetID(random, out uniqueIsNegOne);
                    else
                        r = db.MobileGetPasswordResetID(random, out uniqueIsNegOne);

                    if(r.error)
                        return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);

                    random = Common.CreateSalt(32);
                    random = rgx.Replace(random, "x");
                }

                if (isDJ)
                    r = db.DJSetPasswordReset(ID, random);
                else
                    r = db.MobileSetPasswordReset(ID, random);

                if(r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);

                try
                {
                    string resetURL = websiteAddress + "?DJ=" + isDJ.ToString() + "&key=" + random;
                    MailMessage mail = GeneratePasswordResetEmail(email, resetURL);
                    SmtpClient mailServer = new SmtpClient("smtp.live.com");
                    mailServer.Port = 25;
                    mailServer.UseDefaultCredentials = false;
                    mailServer.Credentials = new System.Net.NetworkCredential(Settings.EMAIL_ADR, Settings.EMAIL_PSWD);
                    mailServer.EnableSsl = true;
                    mailServer.Send(mail);
                    return r;
                }
                catch (Exception e)
                {
                    r.setErMsgStk(true, e.Message, e.StackTrace);
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_EMAIL_SERVER, Common.LogFile.Web);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Sends the username associated with the email address listed to the email address.
        /// </summary>
        /// <param name="email">The email address of the user.</param>
        /// <param name="role">The role: DJ or Mobile</param>
        /// <returns>The outcome of the operation.</returns>
        public Response SendEmailWithUsername(string email)
        {
            ExpResponse r = new ExpResponse();
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                r = db.OpenConnection();
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);

                List<string> DJUsernames;
                List<string> mobileUsernames;

                r = db.DJGetUsernamesByEmail(email, out DJUsernames);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);

                r = db.MobileGetUsernamesByEmail(email, out mobileUsernames);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);

                if (DJUsernames.Count == 0 && mobileUsernames.Count == 0)
                {
                    r.setErMsg(true, Messages.MSG_EMAIL_NOT_FOUND);
                    return r;
                }

                List<string> usernames = new List<string>();
                List<string> roles = new List<string>();

                foreach (string djUsername in DJUsernames)
                {
                    usernames.Add(djUsername);
                    roles.Add("DJ");
                }
                foreach (string mobileUsername in mobileUsernames)
                {
                    usernames.Add(mobileUsername);
                    roles.Add("Singer");
                }

                try
                {
                    MailMessage mail = GenerateUsernameEmail(email, usernames, roles);
                    SmtpClient mailServer = new SmtpClient("smtp.live.com");
                    mailServer.Port = 25;
                    mailServer.UseDefaultCredentials = false;
                    mailServer.Credentials = new System.Net.NetworkCredential(Settings.EMAIL_ADR, Settings.EMAIL_PSWD);
                    mailServer.EnableSsl = true;
                    mailServer.Send(mail);
                    return r;
                }
                catch (Exception e)
                {
                    r.setErMsgStk(true, e.Message, e.StackTrace);
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_EMAIL_SERVER, Common.LogFile.Web);
                }
            }
        }
示例#4
0
        /// <summary>
        /// "Weblogin" to the system. Returns the user's ID upon success.
        /// </summary>
        /// <param name="username">The username</param>
        /// <param name="password">The password</param>
        /// <param name="role">The role, DJ or Mobile</param>
        /// <param name="ID">Our parameter of the user ID.</param>
        /// <returns>The outcome of the operation.</returns>
        public Response Login(string username, string password, string role, out int ID)
        {
            ID = 0;
            ExpResponse r = new ExpResponse();
            if (!role.Equals("DJ") && !role.Equals("Mobile"))
            {
                r.setErMsgStk(true, "Bad Role Given", Environment.StackTrace);
                return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);
            }

            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                r = db.OpenConnection();
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);

                // Get the salt from the database and salt/hash the password.
                string salt;
                if (role == "DJ")
                    r = db.DJGetSalt(username, out salt);
                else
                    r = db.MobileGetSalt(username, out salt);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_CRED_WRONG, Common.LogFile.Web);
                string saltHashPassword = Common.CreatePasswordHash(password, salt);

                // Check validity of username/password.
                if (role == "DJ")
                    r = db.DJValidateUsernamePassword(username, saltHashPassword);
                else
                    r = db.MobileValidateUsernamePassword(username, saltHashPassword);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);

                // If the username/password couldn't be found, inform user.
                if (r.message.Trim() == string.Empty)
                {
                    r.setErMsg(true, Messages.ERR_CRED_WRONG);
                    return r;
                }

                // Get the ID
                if (!int.TryParse(r.message.Trim(), out ID))
                {
                    r.setErMsgStk(true, "Exception in ChangeEmail: Unable to parse ID from DB!", Environment.StackTrace);
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);
                }

                return r;
            }
        }
示例#5
0
        /// <summary>
        /// Create a playlist. Returns the ID of the playlist in message.
        /// </summary>
        /// <param name="name">Playlist Name</param>
        /// <param name="venueID">VenueID the playlist is associated with.</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileCreatePlaylist(string name, int venueID, long userKey)
        {
            ExpResponse r = new ExpResponse();
            if (name.Length < 1 || name.Length > 20)
            {
                r.setErMsg(true, Messages.ERR_PLYLST_NAME_LONG);
                return r;
            }

            int mobileID = -1;
            int venueStatus;

            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                r = db.OpenConnection();
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                // Convert the userKey to MobileID
                r = MobileKeyToID(userKey, out mobileID, db);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                // Make sure the client isn't already logged out.
                bool validStatus;
                r = MobileCheckStatus(mobileID, "!0", db, out validStatus);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                if (!validStatus)
                {
                    r.setErMsg(true, Messages.ERR_STATUS_IS_NOT_IN);
                    return r;
                }

                // Make sure the venueID exists.
                r = db.DJGetStatus(venueID);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                if (!int.TryParse(r.message.Trim(), out venueStatus))
                {
                    r.setErMsg(true, Messages.ERR_BAD_SERVER_INPUT);
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                }

                r = db.MobileCreatePlaylist(name, venueID, mobileID, DateTime.Now);
                if(r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                return r;
            }
        }
示例#6
0
        /// <summary>
        /// Rate a song.
        /// </summary>
        /// <param name="songID">The songID.</param>
        /// <param name="rating">The rating -1 to 5.</param>
        /// <param name="venueID">The venueID of the song.</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileRateSong(int songID, int rating, int venueID, long userKey)
        {
            int mobileID = -1;
            int venueStatus;
            int songExists;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                ExpResponse r = new ExpResponse();
                if (rating < -1 || rating > 5)
                {
                    r.setErMsg(true, "Rating must be between -1 and 5 (inclusive).");
                    return r;
                }

                // Try to establish a database connection
                r = db.OpenConnection();
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                // Convert the userKey to MobileID
                r = MobileKeyToID(userKey, out mobileID, db);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                // Make sure the client isn't already logged out.
                bool validStatus;
                r = MobileCheckStatus(mobileID, "!0", db, out validStatus);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                if (!validStatus)
                {
                    r.setErMsg(true, Messages.ERR_STATUS_IS_NOT_IN);
                    return r;
                }

                // Make sure the venueID exists.
                r = db.DJGetStatus(venueID);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                if (!int.TryParse(r.message.Trim(), out venueStatus))
                {
                    r.setErMsgStk(true, "MobileGetPlayLists venueID parse fail (Bad venueID given?)", Environment.StackTrace);
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                }

                // Check to see if song exists.
                r = db.SongExists(venueID, songID);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                if (!int.TryParse(r.message.Trim(), out songExists))
                {
                    r.setErMsgStk(true, "Could not find song", Environment.StackTrace);
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                }

                // Set the song rating.
                r = db.MobileSetSongRating(mobileID, songID, rating);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                return r;
            }
        }