123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!DOCTYPE html>

<div class="nav">
    <h3 id="logo">HuddleUp</h3>
    <form method="post" class="signUpInfo">
        <div class="signUp">
            <p>Don't have an account? <a href="/signUp" id="signUp">Sign Up!</a></p>
        </div>
        <div class="loginForm">
            <input class = "email" type="text" name="email" value="Email">
            <input class = "password" type="password" name="password" value="Password">
            <input type="submit" name="" value="SUBMIT" class="submitButton submitLogin">
        </div>
    </form>
</div>

<div class="dropdown">
    <img src="menu.png" alt="" class="dropdown-toggle" data-toggle="dropdown">
    <ul class="dropdown-menu">
        <li><input class="emailDropdown" type="text" name="emailDropdown" value="Email"></li>
        <li><input class="passwordDropdown" type="password" name="passwordDropdown" value="Password"></li>
        <li><input type="submit" name="" value="SUBMIT" class="submitButton submitLoginDropdown"></li>
        <li>
            <div class="signUp">
                <p>Don't have an account?</p>
                <a href="/signUp" class="signUp">Sign Up!</a>
            </div>
        </li>
    </ul>
</div>



<div class="main">
    <p class="tagline">Team Management - simplifed. Create your free account today and start managing your teams!</p>
    <h1 class="headline animated fadeIn">HuddleUp</h1>
</div>

<div class="appInfo container-fluid">

    <div class="roster row">
        <div class="icon col-sm-6">
            <img src="/contact-dark.svg" alt="Contact Image" class="iconImage">
        </div>
        <div class="info col-sm-6">
            <h3 class="infoHeading">Team Roster</h3>
            <p>HuddleUp's Team Roster allows you to quickly and easily get the contact information of all the parents on each of your teams.</p>
        </div>
    </div>

    <div class="scheduling row">
        <div class="info col-sm-6">
            <h3 class="infoHeading">Scheduling</h3>
            <p>Keep track of all your teams upcoming events. Only coaches can add events so you know you've got the correct schedule.</p>
        </div>
        <div class="icon col-sm-6">
            <img src="/calendar-dark.svg" alt="Contact Image" class="iconImage">
        </div>
    </div>

    <div class="communication row">
        <div class="icon col-sm-6">
            <img src="/message-dark.svg" alt="Contact Image" class="iconImage">
        </div>
        <div class="info col-sm-6">
            <h3 class="infoHeading">Communication</h3>
            <p>Keep in touch with all your teams with HuddleUp's message application. Coaches can send realtime text message to parents so you never miss a last minute update.</p>
        </div>
    </div>

    <div class="scheduling row">
        <div class="info col-sm-6">
            <h3 class="infoHeading">Photos</h3>
            <p>HuddleUp makes it easy to share team photos. Upload photos from each of your games and events!</p>
        </div>
        <div class="icon col-sm-6">
            <img src="/camera.svg" alt="Contact Image" class="iconImage">
        </div>
    </div>

</div>

            
          
!
            
              body {
    box-sizing: border-box;
    font-family: 'Open Sans', sans-serif;
}

/****************************
        HOME PAGE
 *****************************/
/* Navigation Bar */
.nav {
    background-color: white;
    width: 100%;
    float: left;
    height: 75px;
}
.dropdown {
    display: none;
}
#logo {
    display: block;
    color: #11213a;
    letter-spacing: 0.02em;
    display: inline-block;
    float: left;
    padding-left: 23px;
    font-family: 'Graduate', cursive;
}
.loginForm {
    display: block;
    float: right;
    clear: right;
    padding: 0 7px 13px 0;
}
.loginForm input {
    padding: 5px 15px;
    font-size: 13px;
}
.signUp {
    float: right;
    display: block;
}
.signUp p {
    margin: 0;
    padding: 2px 0 5px 0;
}
.loginForm, .signUp {
    padding-right: 10px;
}
.submitButton {
    border-radius: 3px;
    font-weight: 700;
    letter-spacing: 0.1em;
    background-color: #3D89D3;
    border: none;
    padding: 7px 22px;
    color: white;
}
.submitButton:hover {
    text-decoration: none;
    color: white;
}
input:-webkit-autofill {
    -webkit-box-shadow: 0 0 0px 1000px white inset;
}

/* Homepage Background Image */
.main {
    clear: both;
    height: 550px;
    background-image: url('/huddle.jpg');
    background-size: cover;
    background-position: center;
}
.headline {
    font-family: 'Graduate', cursive;
    color: white;
    font-size: 87px;
    margin: 0;
    position: absolute;
    top: 15%;
    left: 52%;
    -webkit-text-stroke-width: 2px;
    -webkit-text-stroke-color: black;
}
.tagline {
    color: white;
    width: 300px;
    font-size: 16px;
    position: absolute;
    top: 28%;
    left: 58%;
    text-align: center;
}

/* Info boxes */
.roster, .scheduling, .communication {
    color: white;
    background-color: #777d84;
}
.infoHeading {
    letter-spacing: 0.1em;
    margin-bottom: 24px;
    text-align: center;
    font-family: 'Graduate', cursive;
}

.icon {
    background-color: white;
    /*background-color: #1C2027;*/
    text-align: center;
}
.iconImage {
    height: 150px;
}
.icon, .info {
    height: 331px;
    padding: 65px;
}
.info p {
    line-height: 27px;
    letter-spacing: 0.01em;
}

/* Footer */
.footer {
    padding-top: 60px;
    text-align: center;
    height: 200px;
    background-color: #eaebed;
}
.footer img {
    padding-bottom: 20px;
    display: block;
    margin: 0 auto;
    width: 45px;
}



/****************************
        USER HOME
 *****************************/
.logoLink {
    color: black;
}
.logoLink:hover {
    text-decoration: none;
}
.navUser {
    padding-top: 20px;
}
.navUser h3 {
    margin: 0;
}
.navUser p {
    margin: 0;
}
#logout {
    display: block;
    margin-bottom: 12px;
}
.welcome {
    display: block;
    float: right;
    text-align: right;
    padding-right: 10px;
}
.background {
    clear: both;
    height: 275px;
    background-image: url('/ball6.jpg');
    background-size: cover;
    background-position: top;
}
.myTeams {
    letter-spacing: 0.1em;
    margin-bottom: 24px;
    text-align: center;
    font-family: 'Graduate', cursive;
}
.dashboard {
    min-height: 250px;
    margin: 0 auto;
    display: block;
    text-align: center;
}
.teams {
    width: 250px;
    text-align: left;
    text-align: left;
    margin: 0 auto;
    padding-left: 50px;
}
.trophy {
    margin: 0 auto;
    display: block;
    padding: 20px;
}
.userHomeInfo {
    line-height: 29px;
    padding: 30px;
    max-width: 800px;
    margin: 11px auto -22px;
    font-size: 16px;
}
.teams img {
    height: 16px;
    margin-left: 5px;
    margin-bottom: 4px;
}
.teamButtons {
    padding: 20px;
}
.star {
    display: inline-block;
}


/****************************
        SIGN UP
 *****************************/
.navSignUp {
    padding: 7px 10px 15px;
}
.signUpForm {
    max-width: 500px;
    text-align: left;
    margin-bottom: 30px;
}
.create {
    letter-spacing: 0.1em;
    margin-bottom: 24px;
    text-align: center;
    font-family: 'Graduate', cursive;
}


/****************************
        TEAM HOME
 *****************************/
.teamInfo {
    margin: 0 auto;
    padding: 20px 40px 40px 123px;
     font-size: 16px;
     width: 500px;
     text-align: left;
}
.bold {
    font-weight: 700;
}
.selected {
    background-color: white;
}
body > div.teamNav > ul > li.selected > a {
    color: black;
}
.trophyHome {
    width: 30px;
}
.myHomeLink {
    margin: 20px;
}
.myHomeLink a:hover {
    text-decoration: none;
}
.starDiv {
    margin-top: -15px;
    margin-left: -11px;
}
.starTeamHome {
    margin-top: -4px;
    width: 20px;
    display: inline-block;
}
.coach {
    margin-left: 4px;
    display: inline-block;
}


/****************************
        TEAM ROSTER
 *****************************/
.rosterWrapper {
    padding-top: 20px;
    width: 600px;
    margin: 0 auto;
}
.rosterTable {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 50px;
}

td, th {
    text-align: left;
    padding: 8px;
}

tr:nth-child(even) {
    background-color: #dddddd;
}


/****************************
        EVENTS PAGE
 *****************************/
.eventInfo {
    width: 750px;
}
.eventInfo h4 {
    margin: 16px 16px;
}
.eventInfo p {
    margin-left: 105px;
    margin-bottom: 4px;
}
.eventForm {
    padding-top: 0;
}
.eachEvent{
    padding: 20px;
}
.eachEvent img {
    margin-top: 27px;
    width: 75px;
    float: left;
}
.titleEvent {
    font-weight: 700;
    color: #004390;
    text-decoration: underline;
}
#createEventButton {
    margin-bottom: 47px;
}

/****************************
        MESSAGES PAGE
 *****************************/
.messageBoard {
    margin: 0 auto;
    padding: 20px 40px 13px 123px;
    font-size: 16px;
    width: 700px;
    text-align: left;
}
.messageBoard img {
    margin-top: 23px;
    width: 75px;
    float: left;
}
.messageBoard p {
    margin-left: 105px;
    margin-bottom:0;
    line-height: 25px;
}
.eachMessage {
    padding: 20px;
}
#createMessageButton {
    margin: 0 auto;
    display: block;
    margin-bottom: 40px;
}


/****************************
        TEAM NAVIGATION BAR
 *****************************/
.teamNav ul {
    margin-left: -40px;
    list-style-type: none;
    text-align: center;
    background-color: #3f7cba;
}
.teamNav li {
    display: inline-block;

    margin-left: -4px;
}
.teamNav li a {
    display: inline-block;
    padding: 20px;
    color: white;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 700;
}
.teamNav li a:hover {

    text-decoration: none;
    /*background-color: white;*/
    color: black;
}
.teamNav li:hover {
    background-color: white;
    color: #004390;
}




/****************************
    SWEET ALERT STYLES
 *****************************/
.swalLabel {
    margin-bottom: 0;
    font-weight: 700;
    text-align: left;
}


/****************************
    PHOTOS
 *****************************/

#uploadWidget > div > span:before {
    content: 'Click or Drag and ';
}
#uploadWidget {
    width: 200px;
    margin: 0 auto;
}
.photoSubmit {
    margin: 20px;
}
.eachPhoto {
    display: inline-block;

}
.eachPhoto img {
    width: 400px;
    border-radius: 5px;
    margin: 0 10px 30px 10px;
}



/****************************
    MEDIA QUERIES
*****************************/
@media screen and (max-width: 900px) {
    .headline {
        font-size: 84px;
        left: 41%;
    }
    .tagline {
        left: 50%;
        top: 26%;
    }
    .signUpForm {
        width: 85%;
    }
}

@media screen and (max-width: 791px) {
    .headline {
        font-size: 80px;
    }
    .tagline {
        left: 50%;
    }

}
 /* iPad */
@media screen and (max-width: 768px) {
    .icon, .info {
        height: 250px;
        padding: 38px 48px;
        text-align: center;
    }
    .iconImage {
        height: 112px;
        margin-top: 20px;
    }
    .headline {
        font-size: 66px;
    }
    .tagline {
        top: 24%;
        left: 43%;
    }
    .myHomeLink {
        text-align: center;
    }
    .signUpInfo {
        display: none;
    }
    .dropdown {
        display: block;
    }
    .dropdown-menu {
        position: absolute;
        top: 72px;
        left: 70%;
        padding: 28px;
    }
    .dropdown-menu li {
        text-align: center;
    }
    .dropdown-menu input {
        margin: 10px auto;
        padding: 10px;
    }
    .dropdown img {
        width: 42px;
        float: right;
        position: absolute;
        top: 14px;
        left: 89%;
    }
}

@media screen and (max-width: 760px) {
    /* Info boxes */
    .roster, .scheduling, .communication {
        display: flex;
        flex-direction: column;
    }
    .scheduling .icon {
        order: 1;
    }
    .scheduling .info {
        order: 2;
    }
}

@media screen and (max-width: 631px) {
    .headline {
        font-size: 55px;
    }
    .tagline {
        top: 22%;
        left: 41%;
        font-size: 15px;
    }
    .dropdown-menu {
        left: 61%;
    }

}
@media screen and (max-width: 550px) {
    .headline {
        font-size: 45px;
    }
    .tagline{
        width: 250px;
        font-size: 14px;
    }
}

/* iPhone 6 plus */
@media screen and (max-width: 414px) {
    .background {
        display: none;
    }
    #logo, .signUp {
        float: none;
    }
    .email, .password {
        border: 1px solid gray;
    }
    .loginForm input {
        padding: 9px 5px;
        font-size: 13px;
    }
    .signUp p {
        padding: 0px 0px 5px 11px;
    }
    .headline {
        font-size: 47px;
        top: 13%;
        left: 34%;
    }
    .tagline {
        top: 22%;
        left: 43%;
        width: 200px;
        font-size: 13px;
    }
    .main {
        height: 400px;
    }
    .teamNav li {
        display: block;
    }
    .teamInfo {
        width: 100%;
        padding: 20px 40px 40px 55px;
    }
    .rosterWrapper {
        width: 100%;
    }
    .myTeams {
        padding: 10px;
    }
    .eventInfo, .eachEvent, .messageBoard, .eachMessage {
        width: 100%
    }
    .eventInfo p, .eachMessage p{
        font-size: 15px;
    }
    .messageBoard {
        padding: 0;
    }
    .eachPhoto img {
        width: 300px;
    }
    .photosUl {
        padding:0;
    }
    .dropdown img {
        left: 86%;
    }
    .dropdown-menu {
        left: 44%;
    }
}


/* iphone 6 */
@media screen and (max-width: 375px) {
    .headline {
        font-size: 39px;
        top: 15%;
        left: 35%;
    }
    .tagline {
        font-size: 14px;
        top: 23%;
        left: 39%;
    }
    .icon, .info {
        padding: 24px 42px;
    }
    .iconImage {
        margin-top: 37px;
    }
    .teamInfo {
        padding: 20px;
    }
    .eachMessage p, .eachEvent p {
        font-size: 13px;
    }
    .dropdown-menu {
        left: 38%;
    }
}


/* iphone 5 */
@media screen and (max-width: 320px) {
    .headline {
        left: 28%;
        top: 18%;
    }
    .tagline {
        top: 27%;
    }
    .iconImage {
        height: 112px;
        margin-top: 56px;
        height: 91px;
    }
    .dropdown-menu {
        left: 27%;
    }
    .dropdown img {
        left: 82%;
    }
    .icon, .info {
        padding: 23px 18px;
    }
    td, th {
        padding: 5px;
        font-size: 12px;
    }
    .messageBoard p {
        line-height: 21px;
    }

}

            
          
!
            
              /*jshint esversion: 6 */
const express = require('express');
var multer = require('multer');
const app = express();
var Promise = require('bluebird');
var pgp = require('pg-promise')({promiseLib: Promise});
const bodyParser = require('body-parser');
var twilioConfig = require('./config/twilio-config.js');
var twilioClient = twilioConfig.twilioClient;
var config = require('./config/dbc.js');
var db = pgp({
    host: config.host,
    database: config.database,
    user: config.user,
    password: config.password
});
const session = require('express-session');
const bcrypt = require('bcrypt');
app.set('view engine', 'hbs');
var secrets = require('./config/secret.js');
app.use(session({
    secret: secrets.secret,
    cookie: {maxAge: 600000000}
  })
);

var storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, 'public/photos/');
    },
    filename: function (req, file, cb) {
      let extArray = file.mimetype.split("/");
   let extension = extArray[extArray.length - 1];
   cb(null, file.fieldname + '-' + Date.now()+ '.' +extension);
  }
});
var upload = multer({ storage: storage });


// Serve up public files at root
app.use(express.static('public'));

// Add to request object the body values from HTML
app.use(bodyParser.urlencoded({extended: false}));

// Make session automatically available to all hbs files
app.use(function(req, res, next) {
    res.locals.session = req.session;
    next();
});

// Home page / Log in
app.get('/', function(req, res) {
    res.render('homePage.hbs');
});

// Sign up
app.get('/signUp', function(req, res) {
    res.render('signUp.hbs');
});

// Log out
app.get('/logout', function(req, res) {
    req.session.teamName = null;
    req.session.user = null;
    req.session.userId = null;
    req.session.teamId = null;
    req.session.teamsCoached = null;
    res.redirect('/');
});

// Submit Log in details, click button on home page
app.post('/submitLogin', function(req, res, next) {
    var email = req.body.email;
    var password = req.body.password;
    db.one("SELECT id, firstname, email, password FROM parent WHERE email ilike $1", email)
        .then(function(loginDetails) {
            return [loginDetails, bcrypt.compare(password, loginDetails.password)];
        })
        .spread(function(loginDetails, matched) {
            return [loginDetails, matched, db.any(`SELECT team.id FROM team WHERE coachid = $1`, loginDetails.id)];
        })
        .spread(function(loginDetails, matched, coachResults) {
            req.session.teamsCoached = [];
            coachResults.forEach(function(team, idx) {
                req.session.teamsCoached.push(team.id);
            });
            if (matched) {
                req.session.user = loginDetails.firstname;
                req.session.userId = loginDetails.id;
                res.send('match');
            } else {
                res.send('fail');
            }
        })
        .catch(function(err) {
            console.log(err.message);
            res.send('fail');
        });
});

// Sign up, click sign up submit button route
app.post('/signUpInsert', function(req, res, next) {
    var first = req.body.first;
    var last = req.body.last;
    var email = req.body.email;
    var cellPhone = req.body.cellPhone;
    var homePhone = req.body.homePhone;
    var password = req.body.password;
    var confirm = req.body.confirm;
    if (email === '' || password === '' || confirm === '' || first === '' || last === '' || cellPhone === '') {
        res.send('empty');
    } else if (password !== confirm) {
        res.send('not match');
    } else {
        bcrypt.hash(password, 10)
            .then(function(encrypted) {
                return db.one("INSERT into parent values (default, $1, $2, $3, $4, $5, $6) returning parent.id as id", [first, last, cellPhone, homePhone, encrypted, email]);
            })
            .then(function(result) {
                req.session.user = first;
                req.session.userId = result.id;
                res.send('match');
            })
            .catch(function(err) {
                console.log(err.message);
                res.send('fail');
            });
    }
});

// Authenticate log in
app.use(function authentication(req, res, next) {
    if (req.session.user) {
        next();
    } else {
        res.redirect('/');
    }
});

// User home
app.get('/userHome', function(req, res) {
    db.any(`
        select distinct teamname, team.id
        from team
        join childuserteam
        on team.id = childuserteam.teamid
        join parent
        on childuserteam.parent = parent.id
        where parent.id = $1 and team.coachid != $1;`,req.session.userId)
        .then(function(childresult){
          return [childresult, db.any(`select distinct teamname, team.id
          from
          team
          where coachid = $1`, req.session.userId)];
        })
        .spread(function(childresults, coachresults) {
            res.render('userHome.hbs', {
                teams: childresults,
                id: childresults.id,
                coachteams: coachresults,
                coachid: coachresults.id
            });
        })
        .catch(function(err){
            console.log(err.message);
        });
});

// Create team
app.get('/createTeam', function(req, res) {
    res.render('createTeam.hbs');
});

// Join a team path
app.post('/joinTeam', function(req, res) {
    var teamCode = req.body.teamCode;
    var childName = req.body.childName;
    db.one(`select team.id from team where team.teamCode =      $1`,teamCode)
    .then(function(teamid){
        return db.none(`insert into childuserteam values($1,$2,$3, default);`,[req.session.userId, teamid.id, childName]);
    })
    .then(function(){
        res.send('match');
    })
    .catch(function(err){
        console.log(err.message);
    });
});

// Team Home page
app.get('/team/:id', function(req, res, next) {
    let id = req.params.id;
    req.session.teamId = id;
    db.one(`
        select teamname, coachid, description,teamcode, astcoach, parent.firstname, parent.lastname
        from team
        left outer join parent on coachid = parent.id
        where team.id =$1;`, id)
    .then(function(results){
        var isCoach = false;
        req.session.teamName = results.teamname;
        if (req.session.userId === results.coachid){
            isCoach = true;
        }
        res.render('teamHome.hbs', {
            team: results.teamname,
            description: results.description,
            teamcode: results.teamcode,
            astcoach: results.astcoach,
            coachFirst: results.firstname,
            coachLast: results.lastname,
            coach: isCoach,
            id: id
        });
    });


});

// Team Roster
app.get('/roster/:id', function(req, res, next) {
    let id = req.params.id;
        db.any(`select team.teamname, childname, firstname, lastname, cellphone, homephone, email
        from team
        left outer join childuserteam
        on team.id = childuserteam.teamid
        left outer join parent
        on parent.id = childuserteam.parent
        where team.id = $1;`, id)
    .then(function(results) {
        var isCoach;
        if (req.session.teamsCoached.indexOf(parseInt(id)) > -1) {
            isCoach = true;
        } else {
            isCoach = false;
        }
        res.render('roster.hbs', {
            id: id,
            team: results[0].teamname,
            roster: results,
            isCoach: isCoach
        });
    });

});

// Team Events page
app.get('/events/:id', function(req, res, next) {
    var id = req.params.id;
    db.one(`SELECT teamname, coachid FROM team WHERE team.id = $1`, id)
        .then(function(teamInfo) {
            return [teamInfo, db.any(`SELECT * FROM events JOIN team on events.teamid = team.id WHERE team.id = $1 and date > now() order by date, starttime;`, id)];
        })
        .spread(function(teamInfo, results) {
            results.forEach(function(item){item.date = item.date.toDateString();item.starttime = fixTime(item.starttime);item.endtime = fixTime(item.endtime);});
            var isCoach = false;
            if (req.session.userId === teamInfo.coachid) {
                isCoach = true;
            }
            res.render('events.hbs', {
                id: id,
                teamName: teamInfo.teamname,
                events: results,
                coach: isCoach
            });
        })
        .catch(function(err){
            console.log(err.message);
        });
});

// Team Messages page
app.get('/messages/:id', function(req, res, next) {
    var id = req.params.id;
    db.one(`select teamname from team where team.id = $1`, id)
        .then(function(teamName) {
            return [teamName, db.any(`SELECT * FROM messages JOIN team on messages.teamid = team.id join parent on parent.id = messages.sender WHERE team.id = $1`, id)];
        })
        .spread(function(teamName, results) {
            results.forEach(function(item){item.date = item.date.toDateString();item.time = fixTime(item.time);});
            var isCoach;
            if (req.session.teamsCoached.indexOf(parseInt(id)) > -1) {
                isCoach = true;
            } else {
                isCoach = false;
            }
            res.render('messages.hbs', {
                id: id,
                teamName: teamName.teamname,
                messages: results,
                isCoach: isCoach
            });
        })
        .catch(function(err){
            console.log(err.message);
        });
});

//Team Photos page
app.get('/photos/:id', function(req, res, next) {
    var id = req.params.id;
    db.any(`select path, parentId, date from photo where teamId = $1`,req.session.teamId)
        .then(function(results){
          results.forEach(function(item){item.date = item.date.toDateString();});
          var isCoach;
          if (req.session.teamsCoached.indexOf(parseInt(id)) > -1) {
              isCoach = true;
          } else {
              isCoach = false;
          }
          res.render('photos.hbs',{
            id: id,
            photos: results,
            teamName: req.session.teamName,
            isCoach: isCoach
          });
        }).catch(function(err){
            console.log(err.message);
    });
});

//Photo upload
app.post('/photoUpload', upload.single('file'), function(req, res, next) {
  var id = req.body.id;
  db.none(`insert into photo values (default,$1,$2,$3,$4,now())`,[
    req.session.teamId,
    req.session.userId, req.file.path.slice(7),
    req.file.originalname])
  .then(function(){
    res.send('success');
  })
  .catch(function(err){
      console.log(err.message);
  });
});

// Form Submit - add new team route path
app.post('/team/submitNew', function(req, res, next) {
    let teamName = req.body.teamName;
    let category = req.body.category;
    let astCoach = req.body.astCoach;
    let description = req.body.description;
    function genCode() {
        var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        var code = '';
        for (var i = 0; i <= 7; i++) {
            var r = getRandomIntInclusive(0, 25);
            if (i === 3 || i === 5){
                code += '-';
            }
            code += alphabet[r];
        }
        function getRandomIntInclusive(min, max) {
            min = Math.ceil(min);
            max = Math.floor(max);
                return Math.floor(Math.random() * (max - min + 1)) + min;
            }
                return code;
    }
    let teamCode = genCode();
    db.one("insert into team values(default, $1, $2, $3, $4, $5) returning team.id as id", [teamName, req.session.userId, astCoach, teamCode, description])
        .then(function(result) {
            if (req.session.teamsCoached) {
                req.session.teamsCoached.push(result.id);
            } else {
                req.session.teamsCoached = [result.id];
            }
            var response = {
                message: 'successTeam',
                id: result.id
            };
            res.send(response);
        })
        .catch(next);
});

// Form submit - add new event (visible to coach) route path
app.post('/team/createEvent', function(req, res, next) {
    var id = req.session.teamId;
    let title = req.body.title;
    let date = req.body.date;
    let startTime = req.body.startTime;
    let endTime = req.body.endTime;
    let location = req.body.location;
    let comments = req.body.comments;
    db.none(`
    insert into events values(
    default, $1, $2, $3, $4, $5, $6, $7)`,[title, date, startTime, endTime, location, comments, id])
    .then(function(result) {
        res.send('success');
    })
    .catch(function(err){
        console.log(err.message);
        res.send('fail');
    });
});

// Form submit - add new message route path (visible to all)
app.post('/team/addMessage', function(req, res, next) {
    let id = req.session.teamId;
    let sender = req.session.userId;
    let title = req.body.title;
    let message = req.body.message;
    db.none(`insert into messages values (default, $1, $2, $3, $4, default, default)`, [sender, title, message, id])
        .then(function() {
            res.send('successMsg');
        })
        .catch(next);
});

// Ajax request to send a Team Text Message
app.post('/sendTextMessage', function(req, res) {
    var teamId = req.body.teamId;
    var textMessage = req.body.textMessage;
    var testNumbers = ['+14049315804', '+15046169063', '+14044058848', '+14047047634'];
    testNumbers.forEach(function(cellPhoneNumber){
      twilioClient.sms.messages.create({
          to:cellPhoneNumber,
          from:'+16786662282',
          body: textMessage
      }, function(error, message) {

          if (!error) {
              // res.send('success');
              console.log('Success! The SID for this SMS message is:');
              console.log(message.sid);
              console.log('Message sent on:');
              console.log(message.dateCreated);
          } else {
              console.log('Oops! There was an error.');
              // res.send('failure');
          }
      });

    });
    res.send('success');

});

function fixTime(time){
  var hours = parseInt(time.substring(0,2));
  var period = " AM";
  if (hours > 12){
    period = " PM";
    hours = hours - 12;
  }

  time = hours + ":" + time.substring(3,5) + period;
  return time;

}

// Start server
app.listen(5000, function() {
    console.log('Example app listening on port 5000!');
});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console