Code Monkey home page Code Monkey logo

altus-empire's Introduction

GitHub repo size GitHub Contributors GitHub Issues GitHub Forks GitHub Stars

Altus Empire's live link https://altusempire.herokuapp.com/#/

Architecture and Technology

The MERN stack was utilized to create altus-empire. These include MongoDB Atlas as NoSQL database, Express.js as a framework for Node.js, and React/Redux for state management. Also, Google Maps API allows an embedded interactive map, and Amazon Web Services S3 allows for dispensary image storage and display.

Main features

Altus Empire includes an interactive search bar for users to query the dispensary database. This is done by setting a local state within a SearchBar class and setting functions to update this state accordingly. When you set the state with this.setState() it creates another render of the component. This caused the dispensaries to be fetched repeatedly causing an extra re-render on the map. Debounce is utilized to solve the issue of repeated re-rendering and prevent instant state change.

class SearchBar extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            query: "",
            focus: false
        }

        this.handleSubmit = this.handleSubmit.bind(this)
        this.update = this.update.bind(this)
        this.handleFocus = this.handleFocus.bind(this)
        this.handleBlur = this.handleBlur.bind(this)
        this.storeKeyWord = debounce(this.props.storeKeyWord, 200)
    }

    update(e) {
        this.setState({ query: e.target.value }, this.handleSubmit);
    }

    handleFocus() {
        this.setState({ focus: true })
    }

    handleBlur() {
        this.setState({ focus: false })
    }

    handleSubmit(e) {
        if (this.state.query === "") {
            this.props.fetchDispensaries();
        } else this.props.fetchSearchByNameDispensary(this.state.query)
    }

    render() {

        const { results } = this.props

        return (
                <div className="search-bar" onFocus={this.handleFocus} onBlur={this.handleBlur}>
                    <form onSubmit={this.handleSubmit} className="search-input">
                        <FontAwesomeIcon icon={faSearch} />
                        <input type="text" placeholder="Find a dispensary near you" onChange={this.update} />
                        <button className="map-search-button" onClick={this.handleSubmit}>Search</button>
                    </form>
                </div>
        )
    }
}

On line 85, we ensured that users would not be able to register with the same e-mail. This would ensure users to not be able to create more than one account per e-mail. A status 400 on line 88 would be returned, otherwise, the user would be created if all the credentials were entered correctly. Bcrypt is used for the authentication process.

router.post('/register', (req, res) => {
    const { errors, isValid } = validateRegisterInput(req.body);
    
    if (!isValid) {
        return res.status(400).json(errors);
    }
    
    User.findOne({ email: req.body.email })
        .then(user => {
85          if (user) {
                return res.status(400).json({ email: "A user has already registered with this address" })
            } else {
88              const newUser = new User({
                    username: req.body.username,
                    email: req.body.email,
                    password: req.body.password,
                    dob: req.body.dob,
                })

                bcrypt.genSalt(10, (err, salt) => {
                    bcrypt.hash(newUser.password, salt, (err, hash) => {
                        if (err) throw err;
                        newUser.password = hash;
                        newUser.save()
                            .then(user => {
                                const payload = { id: user.id, username: user.username };

                                jwt.sign(payload, keys.secretOrKey, { expiresIn: 3600 }, (err, token) => {
                                    res.json({
                                        success: true,
                                        token: "Bearer " + token
                                    });
                                });
                            })
                            .catch(err => res.send(err));
                    })
                })
            }
        })
})

Installing altus-empire

To install altus-empire, follow these steps for Linux and macOS:

# Clone repository:

git clone https://github.com/gretahayes19/altus-empire.git

# Run the following command in both the root directory and frontend directory:

npm install 

Contributing to altus-empire

To contribute to altus-empire, follow these steps:

  1. Fork this repository.
  2. Create a branch: git checkout -b <branch_name>.
  3. Make your changes and commit them: git commit -m '<commit_message>'
  4. Push to the original branch: git push origin altus-empire/<location>
  5. Create the pull request.

Alternatively, see the GitHub documentation on creating a pull request.

Contributors

Thanks to the following people who have contributed to this project:

ae (Left to right) Christine Yang, Greta Hayes, Hank Chen, Kevin Mao

altus-empire's People

Contributors

gretahayes19 avatar hankc97 avatar kevinxmao avatar yangc95 avatar

Stargazers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.