示例#1
0
        public JsonResult NewUser(User user)
        {
            user.PortfolioID = portfolioSql.createNewPortfolioID();
            int userId = userSql.addNewUser(user);
            if (userId != -1)
            {
                //Add Free Trial Date
                String today = userSql.createTrialAccount(userId.ToString());

                if (today != null)
                {
                    user.UserID = userId.ToString();
                    Session["user"] = user;
                    Session["trialDate"] = today;
                    return Json(true);
                }
                else
                {
                    return Json(false);
                }
            }
            else
            {
                portfolioSql.deletePortfolioID(user.PortfolioID);
            }
            return Json(false);
        }
示例#2
0
        public int addNewUser(User user)
        {
            int userId = -1;

            if (Open()) {

                MySqlCommand cmd = new MySqlCommand("insert into passwordInformation(passwordHash, salt) VALUES (@passwordHash, @passwordSalt); " +
                    "select LAST_INSERT_ID();", conn);

                cmd.Prepare();
                cmd.Parameters.AddWithValue("@passwordHash", user.PasswordHash);
                cmd.Parameters.AddWithValue("@passwordSalt", user.Salt);

                object passwordIdRet = cmd.ExecuteScalar();

                if (passwordIdRet != null) {
                    if (user.CompanyName == null) {
                        user.CompanyName = "None";
                    }

                    int passwordID = Convert.ToInt32(passwordIdRet);

                    /*Stripe Creation*/
                    StripeObject accessorReturn = stripeAccessor.CreateCustomer(user.Email, user.FirstName, user.LastName);

                    if (accessorReturn is StripeCustomer)
                    {
                        StripeCustomer createdCustomer = (StripeCustomer)accessorReturn;

                        /*Construct Insert Statement*/
                        String query = "insert into users(stripeID, username, firstName, lastName, passwordID, address, zip, email, birthdate, companyName, portfolioID, status) VALUES ";
                        query += "(@stripeID, @username, @firstName, @lastName, @passwordID, @address, @zip, @email, @birthday, @companyName, @portfolioID, @status); select LAST_INSERT_ID();";

                        cmd.CommandText = query;
                        cmd.Prepare();
                        cmd.Parameters.AddWithValue("@stripeID", createdCustomer.Id);
                        cmd.Parameters.AddWithValue("@username", user.Username);
                        cmd.Parameters.AddWithValue("@firstName", user.FirstName);
                        cmd.Parameters.AddWithValue("@lastName", user.LastName);
                        cmd.Parameters.AddWithValue("@passwordID", passwordID);
                        cmd.Parameters.AddWithValue("@address", user.Address);
                        cmd.Parameters.AddWithValue("@zip", user.Zipcode);
                        cmd.Parameters.AddWithValue("@email", user.Email);
                        cmd.Parameters.AddWithValue("@birthday", user.Birthday);
                        cmd.Parameters.AddWithValue("@companyName", user.CompanyName);
                        cmd.Parameters.AddWithValue("@portfolioID", user.PortfolioID);
                        cmd.Parameters.AddWithValue("@status", status.freeTrial);

                        /*Execute Scalar returns the id of the user added, null otherwise*/
                        object userIdRet = cmd.ExecuteScalar();
                        Close();

                        user.stripeObject = createdCustomer;

                        if (userIdRet != null)
                        {
                            userId = Convert.ToInt32(userIdRet);
                        }
                    }
                } else {
                    /*Failed to Insert Password*/
                    Close();
                }
            }
            return userId;
        }
示例#3
0
        public User getUser(String usernameOrEmail)
        {
            User user = null;
            if (Open()) {
                MySqlCommand cmd = new MySqlCommand("select * from users U where (U.username = @username or U.email = @email);", conn);
                cmd.Prepare();
                cmd.Parameters.AddWithValue("@username", usernameOrEmail);
                cmd.Parameters.AddWithValue("@email", usernameOrEmail);

                MySqlDataReader reader = cmd.ExecuteReader();
                if (reader.Read()) {
                    StripeObject stripeObj = stripeAccessor.GetCustomer((string)reader["stripeID"]);
                    if (stripeObj is StripeCustomer)
                    {
                        StripeCustomer customerObj = (StripeCustomer)stripeObj;
                        user = new User();
                        user.UserID = reader["customerID"] + "";
                        user.Username = reader["username"] + "";
                        user.FirstName = reader["firstName"] + "";
                        user.LastName = reader["lastName"] + "";
                        user.Email = reader["email"] + "";
                        user.Address = reader["address"] + "";
                        user.Zipcode = reader["zip"] + "";
                        user.CompanyName = reader["companyName"] + "";
                        user.PictureURL = reader["pictureURL"] + "";
                        user.Birthday = DateTime.Parse(reader["birthDate"] + "");
                        user.stripeId = reader["stripeID"] + "";
                        user.stripeObject = customerObj;
                        user.PortfolioID = Convert.ToInt32(reader["portfolioID"]);
                    }

                }
                reader.Close();

                Close();
            }
            return user;
        }