Skip to content

Commit 1c713e3

Browse files
committed
Merge branch 'principal' of https://github.com/timitoc/LearningPointers into principal
2 parents 3e935f4 + 9f9e90e commit 1c713e3

File tree

5 files changed

+73
-50
lines changed

5 files changed

+73
-50
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ programs/
55
.env
66
*.swp
77
static/avatars/*
8+
npm-debug.log

DatabaseApi/src/db_sql_api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class DbApi {
123123
getAllMyCourses(userId) {
124124
return new Promise((resolve, reject) => {
125125
this.connection.query(
126-
`SELECT user_id, course_id, courses.name as course_name, avg_rating
126+
`SELECT user_id, course_id, courses.url as course_url, courses.name as course_name, avg_rating
127127
FROM users JOIN user_courses ON users.id = user_id JOIN courses ON course_id=courses.id
128128
WHERE users.id=?
129129
ORDER BY avg_rating DESC;`,

npm-debug.log

Lines changed: 0 additions & 45 deletions
This file was deleted.

routes.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module.exports = (app) => {
2727
app.get('/', (req, res) => {
2828
if(req.session.user) {
2929
dbApi.getAllMyCourses(req.session.user.id).then(data => {
30+
console.log(data);
3031
res.render("dashboard", {
3132
user: req.session.user,
3233
subscribed_courses: data
@@ -187,8 +188,26 @@ module.exports = (app) => {
187188
});
188189

189190

190-
app.get('/profile', checkAuth, (req, res) => {
191-
res.render("profile");
191+
app.get('/profile', checkAuth, _csrf, (req, res) => {
192+
res.render("profile", {
193+
user: req.session.user,
194+
csrfToken: req.csrfToken()
195+
});
196+
});
197+
198+
app.post('/profile', checkAuth, _csrf, (req, res) => {
199+
if(!req.body.current_password) {
200+
req.flash('error', 'Password required!');
201+
return res.redirect('/profile');
202+
}
203+
dbApi.loginUser(req.user.email, req.body.current_password)
204+
.then(data => {
205+
res.redirect('/');
206+
})
207+
.catch(err => {
208+
req.flash('error', 'Incorrect password!');
209+
return res.redirect('/profile');
210+
});
192211
});
193212

194213
app.get('/contribute', checkAuth, _csrf, (req, res) => {

views/profile.ejs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@
33
<head>
44
<meta charset="UTF-8">
55
<title></title>
6+
<style>
7+
#success {
8+
text-align: center;
9+
color: white;
10+
background: #2ECC40;
11+
padding: 10px;
12+
font-family: 'Open Sans', sans-serif;
13+
}
14+
15+
#errors {
16+
text-align: center;
17+
color: white;
18+
background: #FF4136;
19+
padding: 10px;
20+
font-family: 'Open Sans', sans-serif;
21+
}
22+
</style>
23+
24+
625
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
726
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
827
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
@@ -43,12 +62,41 @@
4362
</nav>
4463

4564
<div class="container">
65+
<form action="/profile" method="post">
66+
<input type="hidden" name="_csrf" value="<%=csrfToken%>">
4667
<div class="card">
4768
<div class="card-block">
48-
<h3 class="card-title">Name</h3>
69+
<p class="card-text row">
70+
<div class="col-lg-3">
71+
<h4>Name:</h4>
72+
</div>
73+
<div class="col-lg-5">
74+
<input type="text" name="name" value="<%=user.name%>" class="form-control"/>
75+
</div>
76+
</p>
4977
</div>
5078
</div>
51-
</div>
79+
<br>
80+
<div class="card">
81+
<div class="card-block">
82+
<p class="card-text row">
83+
<div class="col-lg-3">
84+
<h4>Password:</h4>
85+
</div>
86+
<div class="col-lg-5">
87+
<input type="password" name="current_password" placeholder="Old password (required)"
88+
class="form-control" required/>
89+
</div>
90+
<br>
91+
<div class="col-lg-5">
92+
<input type="password" name="password_new" placeholder="New password" class="form-control"/>
93+
</div>
94+
</p>
95+
</div>
96+
</div>
97+
<br>
98+
<button class="btn btn-primary" type="submit">Save settings</button>
99+
</form>
52100
</div>
53101
</body>
54102
</html>

0 commit comments

Comments
 (0)