Merge branch 'cher' into 'master'
user detail update and more See merge request !8
Showing
6 changed files
with
156 additions
and
117 deletions
... | @@ -37,8 +37,14 @@ npm run dev:server | ... | @@ -37,8 +37,14 @@ npm run dev:server |
37 | ``` | 37 | ``` |
38 | 38 | ||
39 | <br> | 39 | <br> |
40 | + | ||
40 | ### API reference | 41 | ### API reference |
42 | + | ||
41 | [Programming Quotes API](quotes.stormconsultancy.co.uk/random.json) | 43 | [Programming Quotes API](quotes.stormconsultancy.co.uk/random.json) |
42 | <br> | 44 | <br> |
45 | + | ||
46 | +[Trending-GitHub API](https://docs.trending-github.com/) | ||
47 | + | ||
43 | ### License | 48 | ### License |
49 | + | ||
44 | [MIT](https://choosealicense.com/licenses/mit/) | 50 | [MIT](https://choosealicense.com/licenses/mit/) | ... | ... |
... | @@ -47,8 +47,6 @@ const gitTrend = async (req, res) => { | ... | @@ -47,8 +47,6 @@ const gitTrend = async (req, res) => { |
47 | }; | 47 | }; |
48 | }; | 48 | }; |
49 | 49 | ||
50 | - | ||
51 | - | ||
52 | export const handleHome = async (req, res) => { | 50 | export const handleHome = async (req, res) => { |
53 | const quote = await getQuote(); | 51 | const quote = await getQuote(); |
54 | const trend = await gitTrend(); | 52 | const trend = await gitTrend(); |
... | @@ -73,55 +71,64 @@ export const handleHome = async (req, res) => { | ... | @@ -73,55 +71,64 @@ export const handleHome = async (req, res) => { |
73 | 71 | ||
74 | export const getUserDetail = async (req, res) => { | 72 | export const getUserDetail = async (req, res) => { |
75 | const quote = await getQuote(); | 73 | const quote = await getQuote(); |
74 | + const id = req.params.id; | ||
75 | + const user = await User.findById(id); | ||
76 | + console.log(user.tech); | ||
77 | + | ||
76 | res.render("userDetail", { | 78 | res.render("userDetail", { |
77 | pagetTitle: "User Detail", | 79 | pagetTitle: "User Detail", |
78 | quote: quote.quote, | 80 | quote: quote.quote, |
79 | author: quote.author, | 81 | author: quote.author, |
82 | + user, | ||
80 | }); | 83 | }); |
81 | }; | 84 | }; |
82 | 85 | ||
83 | -export const getEditProfile = async (req,res)=> { | 86 | +export const getEditProfile = async (req, res) => { |
84 | - const{ | 87 | + const { |
85 | - user:{_id:id} | 88 | + user: { _id: id }, |
86 | - } = req; | 89 | + } = req; |
87 | - try{ | 90 | + try { |
88 | - const user = await User.findById(id); | 91 | + const user = await User.findById(id); |
89 | - if(user.id !== id){ | 92 | + if (user.id !== id) { |
90 | - throw Error(); | 93 | + throw Error(); |
91 | - } else{ | 94 | + } else { |
92 | - res.render("editProfile",{pageTitle:"Edit Profile", user}); | 95 | + res.render("editProfile", { pageTitle: "Edit Profile", user }); |
93 | - } | ||
94 | - }catch(error){ | ||
95 | - console.log(error); | ||
96 | } | 96 | } |
97 | + } catch (error) { | ||
98 | + console.log(error); | ||
99 | + } | ||
97 | }; | 100 | }; |
98 | 101 | ||
99 | -export const postEditProfile = async (req,res) =>{ | 102 | +export const postEditProfile = async (req, res) => { |
100 | - const { | 103 | + const { |
101 | - user:{_id:id}, | 104 | + user: { _id: id }, |
102 | - body: {name, email, school, blogUrl, tech, career, introduction}, | 105 | + body: { name, email, school, blogUrl, tech, career, introduction }, |
103 | - file | 106 | + file, |
104 | - } = req; | 107 | + } = req; |
105 | - try{ | 108 | + try { |
106 | - const updatedUser = await User.findByIdAndUpdate(id, { | 109 | + const updatedUser = await User.findByIdAndUpdate( |
107 | - avatarUrl: file ? file.path : req.session.passport.user.avatarUrl, | 110 | + id, |
108 | - name, | 111 | + { |
109 | - email, | 112 | + avatarUrl: file ? file.path : req.session.passport.user.avatarUrl, |
110 | - school, | 113 | + name, |
111 | - blogUrl, | 114 | + email, |
112 | - tech: User.formatTech(tech), | 115 | + school, |
113 | - career: User.formatCareer(career), | 116 | + blogUrl, |
114 | - introduction | 117 | + tech: User.formatTech(tech), |
115 | - }, | 118 | + career: User.formatCareer(career), |
116 | - { | 119 | + introduction, |
117 | - new: true | 120 | + }, |
118 | - }); | 121 | + { |
119 | - req.session.passport.user = updatedUser; | 122 | + new: true, |
120 | - res.redirect("/users/edit-profile"); | 123 | + } |
121 | - }catch(error){ | 124 | + ); |
122 | - console.log(error); | 125 | + req.session.passport.user = updatedUser; |
123 | - res.redirect("/"); | 126 | + //console.log(updatedUser); |
124 | - } | 127 | + res.redirect("/users/edit-profile"); |
128 | + } catch (error) { | ||
129 | + console.log(error); | ||
130 | + res.redirect("/"); | ||
131 | + } | ||
125 | }; | 132 | }; |
126 | 133 | ||
127 | export const getJoin = (req, res) => { | 134 | export const getJoin = (req, res) => { |
... | @@ -151,26 +158,25 @@ export const githubLoginCallback = async (_, __, profile, done) => { | ... | @@ -151,26 +158,25 @@ export const githubLoginCallback = async (_, __, profile, done) => { |
151 | }, | 158 | }, |
152 | } = profile; | 159 | } = profile; |
153 | 160 | ||
154 | - try{ | 161 | + try { |
155 | - const user = await User.findOne({githubId}); | 162 | + const user = await User.findOne({ githubId }); |
156 | - if(user){ | 163 | + if (user) { |
157 | - user.githubId = githubId, | 164 | + (user.githubId = githubId), (user.githubName = githubName); |
158 | - user.githubName = githubName | 165 | + await user.save(); |
159 | - await user.save(); | 166 | + return done(null, user); |
160 | - return done(null, user); | 167 | + } else { |
161 | - }else{ | 168 | + const newUser = await User.create({ |
162 | - const newUser = await User.create({ | 169 | + githubId, |
163 | - githubId, | 170 | + githubName, |
164 | - githubName, | 171 | + avatarUrl, |
165 | - avatarUrl, | 172 | + name, |
166 | - name, | 173 | + email, |
167 | 174 | + }); | |
168 | - }); | 175 | + return done(null, newUser); |
169 | - return done(null, newUser); | ||
170 | - } | ||
171 | - }catch(error){ | ||
172 | - return done(error); | ||
173 | } | 176 | } |
177 | + } catch (error) { | ||
178 | + return done(error); | ||
179 | + } | ||
174 | }; | 180 | }; |
175 | 181 | ||
176 | export const postGithubLogin = (req, res) => { | 182 | export const postGithubLogin = (req, res) => { | ... | ... |
1 | import mongoose from "mongoose"; | 1 | import mongoose from "mongoose"; |
2 | 2 | ||
3 | const UserSchema = new mongoose.Schema({ | 3 | const UserSchema = new mongoose.Schema({ |
4 | - name: { | 4 | + name: { |
5 | - type: String, | 5 | + type: String, |
6 | - trim: true | 6 | + trim: true, |
7 | - }, | 7 | + }, |
8 | - email: { | 8 | + email: { |
9 | - type: String, | 9 | + type: String, |
10 | - trim: true, | 10 | + trim: true, |
11 | - unique: true | 11 | + unique: true, |
12 | - }, | 12 | + }, |
13 | - avatarUrl: String, | 13 | + avatarUrl: String, |
14 | - githubId: { | 14 | + githubId: { |
15 | - type: Number, | 15 | + type: Number, |
16 | - required: "GitHub id is required", | 16 | + required: "GitHub ID is required", |
17 | - unique: true | 17 | + unique: true, |
18 | - }, | 18 | + }, |
19 | - githubName: { | 19 | + githubName: { |
20 | - type: String, | 20 | + type: String, |
21 | - required: "Github nickname is required", | 21 | + required: "Github nickname is required", |
22 | - trim: true | 22 | + trim: true, |
23 | - }, | 23 | + }, |
24 | - school: { | 24 | + school: { |
25 | - type: String, | 25 | + type: String, |
26 | - trim: true | 26 | + trim: true, |
27 | - }, | 27 | + }, |
28 | - tech: [{ type: String, trim: true }], | 28 | + tech: [{ type: String, trim: true }], |
29 | - career: [{ type: String, trim: true }], | 29 | + career: [{ type: String, trim: true }], |
30 | - introduction: { type: String, maxLength: 500}, | 30 | + introduction: { type: String, maxLength: 500 }, |
31 | - createdAt: { | 31 | + createdAt: { |
32 | - type: Date, | 32 | + type: Date, |
33 | - default: Date.now | 33 | + default: Date.now, |
34 | - }, | 34 | + }, |
35 | - blogUrl: { | 35 | + blogUrl: { |
36 | - type: String, | 36 | + type: String, |
37 | - default: "#" | 37 | + default: "#", |
38 | - }, | 38 | + }, |
39 | - githubUrl: { | 39 | + githubUrl: { |
40 | - type: String, | 40 | + type: String, |
41 | - default: "#" | 41 | + default: "#", |
42 | - } | 42 | + }, |
43 | }); | 43 | }); |
44 | 44 | ||
45 | -UserSchema.static("formatTech", function(tech){ | 45 | +UserSchema.static("formatTech", function (tech) { |
46 | - return tech.split(","); | 46 | + return tech.split(","); |
47 | }); | 47 | }); |
48 | -UserSchema.static("formatCareer",function(career){ | 48 | +UserSchema.static("formatCareer", function (career) { |
49 | - return career.split(","); | 49 | + return career.split(","); |
50 | }); | 50 | }); |
51 | 51 | ||
52 | const User = mongoose.model("User", UserSchema); | 52 | const User = mongoose.model("User", UserSchema); |
53 | 53 | ||
54 | - | ||
55 | -export default User; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
54 | +export default User; | ... | ... |
1 | import express from "express"; | 1 | import express from "express"; |
2 | -import { getEditProfile, getUserDetail, handleUsers, postEditProfile } from "../controllers/userController"; | 2 | +import { |
3 | + getEditProfile, | ||
4 | + getUserDetail, | ||
5 | + handleUsers, | ||
6 | + postEditProfile, | ||
7 | +} from "../controllers/userController"; | ||
3 | import { onlyPrivate, uploadFiles } from "../middlewares"; | 8 | import { onlyPrivate, uploadFiles } from "../middlewares"; |
4 | 9 | ||
5 | const userRouter = express.Router(); | 10 | const userRouter = express.Router(); |
... | @@ -7,7 +12,12 @@ const userRouter = express.Router(); | ... | @@ -7,7 +12,12 @@ const userRouter = express.Router(); |
7 | userRouter.get("/", handleUsers); | 12 | userRouter.get("/", handleUsers); |
8 | 13 | ||
9 | userRouter.get("/edit-profile", onlyPrivate, getEditProfile); | 14 | userRouter.get("/edit-profile", onlyPrivate, getEditProfile); |
10 | -userRouter.post("/edit-profile", onlyPrivate, uploadFiles.single("photo"),postEditProfile); | 15 | +userRouter.post( |
16 | + "/edit-profile", | ||
17 | + onlyPrivate, | ||
18 | + uploadFiles.single("photo"), | ||
19 | + postEditProfile | ||
20 | +); | ||
11 | 21 | ||
12 | userRouter.get("/:id", getUserDetail); | 22 | userRouter.get("/:id", getUserDetail); |
13 | 23 | ... | ... |
... | @@ -16,7 +16,7 @@ block content | ... | @@ -16,7 +16,7 @@ block content |
16 | else | 16 | else |
17 | a(href=`/users/${loggedUser._id}`) My profile | 17 | a(href=`/users/${loggedUser._id}`) My profile |
18 | 18 | ||
19 | - .gotoTrend(style="border: 1px solid blue;") | 19 | + .gotoTrend(style="border: 1px solid blue;") |
20 | p(style='color: orange;') Trending Repositories: | 20 | p(style='color: orange;') Trending Repositories: |
21 | br | 21 | br |
22 | a(href=Url0, style={color:'grey'}) | 22 | a(href=Url0, style={color:'grey'}) | ... | ... |
... | @@ -11,23 +11,41 @@ block content | ... | @@ -11,23 +11,41 @@ block content |
11 | img(src="#") | 11 | img(src="#") |
12 | .user-profile__link | 12 | .user-profile__link |
13 | a(href="#") Github | 13 | a(href="#") Github |
14 | + |#{' '} | ||
14 | a(href="#") Blog | 15 | a(href="#") Blog |
15 | .user-profile__column | 16 | .user-profile__column |
16 | .user-profile__info | 17 | .user-profile__info |
17 | - h3 NAME | 18 | + h3(style="display: inline;") NAME: |
18 | - h3 GITHUB NICKNAME | 19 | + h4(style="display: inline;")=user.name |
19 | - h3 EMAIL | 20 | + br |
20 | - h3 SCHOOL | 21 | + h3(style="display: inline;") GITHUB NICKNAME: |
21 | - h3 TECH | 22 | + h4(style="display: inline;")=user.githubName |
22 | - h3 CAREER | 23 | + br |
23 | - h3 SELF-INTRODUCTION | 24 | + h3(style="display: inline;") EMAIL: |
25 | + h4(style="display: inline;")=user.email | ||
26 | + br | ||
27 | + h3(style="display: inline;") SCHOOL: | ||
28 | + h4(style="display: inline;")=user.school | ||
29 | + h3 TECH: | ||
30 | + ul | ||
31 | + each tech in user.tech | ||
32 | + li=tech | ||
33 | + h3 CAREER: | ||
34 | + ul | ||
35 | + each career in user.career | ||
36 | + li=career | ||
37 | + h3(style="display: inline;") SELF-INTRODUCTION: | ||
38 | + h4(style="display: inline;")=user.introduction | ||
24 | hr | 39 | hr |
25 | .user-status | 40 | .user-status |
26 | .user-status__contributions | 41 | .user-status__contributions |
27 | - img(src="http://ghchart.rshah.org/lsj8706" alt="Name Your Github chart") | 42 | + img(src=`http://ghchart.rshah.org/${user.githubName}` alt="Name Your Github chart") |
28 | .user-status__character | 43 | .user-status__character |
29 | h3 Your step | commit numbers | 44 | h3 Your step | commit numbers |
30 | img(src="https://preview.free3d.com/img/2019/12/2269306250288170045/1oe8ymrc-900.jpg" alt="character" style="height:200px; width:250px;") | 45 | img(src="https://preview.free3d.com/img/2019/12/2269306250288170045/1oe8ymrc-900.jpg" alt="character" style="height:200px; width:250px;") |
31 | .user-repositories | 46 | .user-repositories |
32 | .user-repo | 47 | .user-repo |
33 | - h3 REPO 1 | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
48 | + h3 REPO 1 | ||
49 | + | ||
50 | + | ||
51 | + | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment