Ejemplo n.º 1
0
        /// <summary>
        /// Registers a DJ for the Mobioke service.
        /// If an error occurs, the response will describe the error.
        /// </summary>
        /// <param name="username">The username to use. Must not be in use by the service already</param>
        /// <param name="password">The password to use.</param>
        /// <param name="venue">Object that describes the DJ's venue.</param>
        /// <param name="email">The email address of the DJ</param>
        /// <returns>A Response object indicating the result of the operation.</returns>
        public Response DJSignUp(string username, string password, Venue venue, string email)
        {
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return r;

                // Escape to allow the DJTestClient to list all DJ information
                // WILL BE REMOVED FOR RELEASE!
                if (username.Equals("list", StringComparison.OrdinalIgnoreCase))
                {
                    Response listResponse = db.DJListMembers();
                    if (listResponse.error)
                        return listResponse;
                    if (r.error)
                        return r;
                    return listResponse;
                }

                // Validate that username and password are not blank.
                if (username.Length == 0 || password.Length == 0)
                {
                    r.error = true;
                    r.message = "Username or password is blank.";
                    return r;
                }

                // Validate that username and password are not too long.
                if (username.Length > 20 || password.Length > 20)
                {
                    r.error = true;
                    r.message = "Username or password is longer than 20 characters.";
                    return r;
                }

                // Try to see if the username already exists. If it does, inform the client.
                r = db.DJValidateUsername(username);
                if (r.error)
                    return r;
                if (r.message.Trim() != string.Empty)
                {
                    r.error = true;
                    r.message = "That username already exists.";
                    return r;
                }

                // Validate the email address.
                try
                {
                    var address = new System.Net.Mail.MailAddress(email);
                }
                catch
                {
                    r.error = true;
                    r.message = "Email address is not valid";
                    return r;
                }

                if (venue == null)
                {
                    r.error = true;
                    r.message = "Venue information must be passed in.";
                    return r;
                }

                if (venue.venueName == null || venue.venueName.Length == 0)
                {
                    r.error = true;
                    r.message = "Venue name must be set";
                    return r;
                }

                if (venue.venueName.Length > 20)
                {
                    r.error = true;
                    r.message = "Venue name is longer than 20 characters.";
                    return r;
                }

                if (venue.venueAddress.Length > 100)
                {
                    r.error = true;
                    r.message = "Venue address is longer than 100 characters";
                    return r;
                }

                if (venue.venueAddress == null || venue.venueAddress.Length == 0)
                {
                    r.error = true;
                    r.message = "Venue address must be set";
                    return r;
                }

                // Information seems valid, create a salt and hash the password.
                string salt = Common.CreateSalt(16);
                string hashSaltPassword = Common.CreatePasswordHash(password, salt);

                // Sign up the user.
                r = db.DJSignUp(username, hashSaltPassword, email, venue.venueName, venue.venueAddress, salt);
                if (r.error)
                    return r;

                return r;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Registers a DJ for the Mobioke service.
        /// If an error occurs, the response will describe the error.
        /// </summary>
        /// <param name="username">The username to use. Must not be in use by the service already</param>
        /// <param name="password">The password to use.</param>
        /// <param name="venue">Object that describes the DJ's venue.</param>
        /// <param name="email">The email address of the DJ</param>
        /// <returns>A Response object indicating the result of the operation.</returns>
        public Response DJSignUp(string username, string password, Venue venue, string email)
        {
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                ExpResponse r = db.OpenConnection();
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);

                // Validate that username and password are not blank.
                if (username.Length == 0 || password.Length == 0)
                {
                    r.setErMsg(true, Messages.ERR_CRED_BLANK);
                    return r;
                }

                // Validate that username and password are not too long.
                if (username.Length > 20 || password.Length > 20)
                {
                    r.setErMsg(true, Messages.ERR_CRED_LONG);
                    return r;
                }

                // Try to see if the username already exists. If it does, inform the client.
                r = db.DJValidateUsername(username);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);
                if (r.message.Trim() != string.Empty)
                {
                    r.setErMsg(true, Messages.ERR_CRED_TAKEN);
                    return r;
                }

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

                if (venue == null)
                {
                    r.setErMsg(true, Messages.ERR_VEN_INFO_MISSING);
                    return r;
                }

                if (venue.venueName == null || venue.venueName.Length == 0)
                {
                    r.setErMsg(true, Messages.ERR_VEN_INFO_MISSING);
                    return r;
                }

                if (venue.venueName.Length > 20)
                {
                    r.setErMsg(true, Messages.ERR_VEN_INFO_LONG);
                    return r;
                }

                if (venue.venueAddress == null || venue.venueAddress.Length == 0)
                {
                    r.setErMsg(true, Messages.ERR_VEN_INFO_MISSING);
                    return r;
                }

                if (venue.venueAddress.Length > 100)
                {
                    r.setErMsg(true, Messages.ERR_VEN_INFO_LONG);
                    return r;
                }

                // Information seems valid, create a salt and hash the password.
                string salt = Common.CreateSalt(16);
                string hashSaltPassword = Common.CreatePasswordHash(password, salt);

                // Sign up the user.
                r = db.DJSignUp(username, hashSaltPassword, email, venue.venueName, venue.venueAddress, salt);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web);

                return r;
            }
        }