Skip to content

Commit

Permalink
added list of profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
tjhickey724 committed Jun 16, 2020
1 parent ba41299 commit 5943eb0
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
33 changes: 32 additions & 1 deletion cs152aj/week3/authdemo/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,40 @@ app.use('/dbdemo',
app.use('/db',dbRouter);
app.use('/todo',toDoRouter);

app.get('/profiles',
isLoggedIn,
async (req,res,next) => {
try {
res.locals.profiles = await User.find({})
res.render('profiles')
}
catch(e){
next(e)
}
}
)

app.get('/publicprofile/userId:',
async (req,res,next) => {
try {
let userId = req.params.userId
res.locals.profile = await User.findOne({_id:userId})
res.render('publicprofile')
}
catch(e){
console.log("Error in /profile/userId:")
next(e)
}
}
)


app.get('/profile',
isLoggedIn,
(req,res) => res.render('profile'))
(req,res) => {
res.render('profile')
})

app.get('/editProfile',
isLoggedIn,
(req,res) => res.render('editProfile'))
Expand Down
1 change: 1 addition & 0 deletions cs152aj/week3/authdemo/views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<li><a href="/dbdemo">See database API </a></li>
<% if (loggedIn) {%>
<li><a href="/profile">See your profile </a></li>
<li><a href="/profiles">See everyone's profile</a></li>
<li><a href="/todo">See your to do list </a></li>
<% } %>
</ul>
Expand Down
15 changes: 15 additions & 0 deletions cs152aj/week3/authdemo/views/profiles.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="jumbotron">
<h1>Registered Users</h1>
<p> this comes from the google authentication
and from the info you provide
</p>
</div>
<hr>
<ol>
<% profiles.forEach(profile => { %>
<li>
<%= profile.googlename %><br>
<%=profile.googleemail %>
</li>
<% }) %>
</ol>
38 changes: 38 additions & 0 deletions cs152aj/week3/authdemo/views/publicprofile.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class="jumbotron">
<h1>Your Profile</h1>
<p> this comes from the google authentication
and from the info you provide when you
edit this page!
</p>
</div>
<hr>
<a href="editProfile">Edit</a>
<hr>
<div class="row">
<div class="col-sm-4">
</div>
<div class="col-sm-4">
<table class="table table-bordered">
<tbody>
<tr>
<td>googlename</td>
<td><%= profile.googlename %> </td>
</tr>
<tr>
<td>googleemail</td>
<td> (hidden) </td>
</tr>
<tr>
<td>username</td>
<td><%= profile.username %> </td>
</tr>
<tr>
<td>age</td>
<td><%= profile.age %> </td>
</tr>
</tbody>
</table>
</div>
<div class="col-sm-4">
</div>
</div>

0 comments on commit 5943eb0

Please sign in to comment.