Toggle navigation
Toggle navigation
This project
Loading...
Sign in
이세진
/
dev-profile
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
10
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Lee SeJin
2021-05-23 19:02:51 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
dc5bc267058fc2d576e2d866f926e7672c89ec51
dc5bc267
1 parent
1f36c8a4
edit profile update
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
87 additions
and
25 deletions
.gitignore
package.json
src/controllers/userController.js
src/middlewares.js
src/models/User.js
src/routers/globalRouter.js
src/routers/userRouter.js
src/server.js
src/views/editProfile.pug
src/views/home.pug
src/views/join.pug
src/views/login.pug
src/views/partials/footer.pug
src/views/partials/header.pug
.gitignore
View file @
dc5bc26
...
...
@@ -117,6 +117,6 @@ dist
.pnp.*
package-lock.json
uploads
/
uploads
static
build
\ No newline at end of file
...
...
package.json
View file @
dc5bc26
...
...
@@ -22,6 +22,7 @@
"express-session"
:
"^1.17.1"
,
"mongoose"
:
"^5.12.9"
,
"morgan"
:
"^1.10.0"
,
"multer"
:
"^1.4.2"
,
"nodemon"
:
"^2.0.7"
,
"passport"
:
"^0.4.1"
,
"passport-github2"
:
"^0.1.12"
,
...
...
src/controllers/userController.js
View file @
dc5bc26
...
...
@@ -23,11 +23,48 @@ export const getUserDetail = async (req,res) =>{
res
.
render
(
"userDetail"
,{
pagetTitle
:
"User Detail"
,
quote
:
quote
.
quote
,
author
:
quote
.
author
})
}
export
const
getEditProfile
=
(
req
,
res
)
=>
res
.
render
(
"editProfile"
,{
pageTitle
:
"Edit Profile"
});
export
const
getEditProfile
=
async
(
req
,
res
)
=>
{
const
{
user
:{
_id
:
id
}
}
=
req
;
try
{
const
user
=
await
User
.
findById
(
id
);
if
(
user
.
id
!==
id
){
throw
Error
();
}
else
{
res
.
render
(
"editProfile"
,{
pageTitle
:
"Edit Profile"
,
user
});
}
}
catch
(
error
){
console
.
log
(
error
);
}
};
export
const
postEditProfile
=
(
req
,
res
)
=>
{
console
.
log
(
req
.
body
);
export
const
postEditProfile
=
async
(
req
,
res
)
=>
{
const
{
user
:{
_id
:
id
},
body
:
{
name
,
email
,
school
,
blogUrl
,
tech
,
career
,
introduction
},
file
}
=
req
;
try
{
const
updatedUser
=
await
User
.
findByIdAndUpdate
(
id
,
{
avatarUrl
:
file
?
file
.
path
:
req
.
session
.
passport
.
user
.
avatarUrl
,
name
,
email
,
school
,
blogUrl
,
tech
:
User
.
formatTech
(
tech
),
career
:
User
.
formatCareer
(
career
),
introduction
},
{
new
:
true
});
req
.
session
.
passport
.
user
=
updatedUser
;
res
.
redirect
(
"/users/edit-profile"
);
}
catch
(
error
){
console
.
log
(
error
);
res
.
redirect
(
"/"
);
}
};
...
...
@@ -49,7 +86,7 @@ export const githubLoginCallback = async (_, __, profile, done) =>{
const
{
_json
:
{
id
:
githubId
,
login
:
githubName
,
avatar_url
:
avatarUrl
,
name
,
email
}}
=
profile
;
try
{
const
user
=
await
User
.
findOne
({
email
});
const
user
=
await
User
.
findOne
({
githubId
});
if
(
user
){
user
.
githubId
=
githubId
,
user
.
githubName
=
githubName
...
...
src/middlewares.js
View file @
dc5bc26
import
multer
from
"multer"
;
export
const
localsMiddleware
=
(
req
,
res
,
next
)
=>
{
res
.
locals
.
siteName
=
"Dev Profile"
;
res
.
locals
.
loggedUser
=
req
.
user
||
null
;
...
...
@@ -20,3 +22,10 @@ export const onlyPrivate = (req, res, next) => {
res
.
redirect
(
"/"
);
}
};
export
const
uploadFiles
=
multer
({
dest
:
"uploads/"
,
limits
:
{
fileSize
:
3000000
}
});
\ No newline at end of file
...
...
src/models/User.js
View file @
dc5bc26
...
...
@@ -27,7 +27,7 @@ const UserSchema = new mongoose.Schema({
},
tech
:
[{
type
:
String
,
trim
:
true
}],
career
:
[{
type
:
String
,
trim
:
true
}],
introduction
:
String
,
introduction
:
{
type
:
String
,
maxLength
:
500
}
,
createdAt
:
{
type
:
Date
,
default
:
Date
.
now
...
...
src/routers/globalRouter.js
View file @
dc5bc26
...
...
@@ -12,9 +12,10 @@ globalRouter.get("/join", onlyPublic, getJoin);
globalRouter
.
get
(
"/login"
,
onlyPublic
,
getLogin
);
globalRouter
.
get
(
"/logout"
,
onlyPrivate
,
logout
);
globalRouter
.
get
(
"/auth/github"
,
githubLogin
);
globalRouter
.
get
(
"/auth/github"
,
onlyPublic
,
githubLogin
);
globalRouter
.
get
(
"/auth/github/callback"
,
onlyPublic
,
passport
.
authenticate
(
"github"
,{
failureRedirect
:
"/login"
}),
postGithubLogin
);
...
...
src/routers/userRouter.js
View file @
dc5bc26
import
express
from
"express"
;
import
{
getEditProfile
,
getUserDetail
,
handleUsers
,
postEditProfile
}
from
"../controllers/userController"
;
import
{
onlyPrivate
}
from
"../middlewares"
;
import
{
onlyPrivate
,
uploadFiles
}
from
"../middlewares"
;
const
userRouter
=
express
.
Router
();
...
...
@@ -8,7 +8,7 @@ const userRouter = express.Router();
userRouter
.
get
(
"/"
,
handleUsers
);
userRouter
.
get
(
"/edit-profile"
,
onlyPrivate
,
getEditProfile
);
userRouter
.
post
(
"/edit-profile"
,
onlyPrivate
,
postEditProfile
);
userRouter
.
post
(
"/edit-profile"
,
onlyPrivate
,
uploadFiles
.
single
(
"photo"
),
postEditProfile
);
userRouter
.
get
(
"/:id"
,
getUserDetail
);
...
...
src/server.js
View file @
dc5bc26
...
...
@@ -32,6 +32,7 @@ app.use(passport.initialize());
app
.
use
(
passport
.
session
());
app
.
use
(
localsMiddleware
);
app
.
use
(
"/uploads"
,
express
.
static
(
"uploads"
));
app
.
use
(
"/"
,
globalRouter
);
app
.
use
(
"/users"
,
userRouter
);
...
...
src/views/editProfile.pug
View file @
dc5bc26
...
...
@@ -2,15 +2,23 @@ extends layouts/main
block content
.form-container
form(action="/users/edit-profile", method="POST", enctype="application/json")
form(action="/users/edit-profile", method="POST", enctype="multipart/form-data")
img(src=`/${loggedUser.avatarUrl}`, width="100", height="120")
.fileUpload
label(for="picture") Picture
input(type="file", id="picture", name="picture", accept="image/*")
input(type="text", placeholder="Name", name="name")
input(type="text", placeholder="Github Id", name="githubId")
input(type="email", placeholder="Email", name="email")
input(type="text", placeholder="School", name="school")
textarea(name="tech", placeholder="Add your Tech")
textarea(name="career", placeholder="Add your Career")
textarea(name="introduction", placeholder="Self introduction")
label(for="photo") Photo
input(type="file", id="photo", name="photo", accept="image/*")
label(for="name") Name
input(type="text", id="name",placeholder="Name", name="name", value=user.name)
label(for="email") Email
input(type="email", id="email", placeholder="Email", name="email", value=user.email)
label(for="school") School
input(type="text", id="school",placeholder="School", name="school", value=user.school)
label(for="blogUrl") Blog Url
input(type="text", id="blogUrl", placeholder="Blog url", name="blogUrl", value=user.blogUrl)
label(for="tech") Enter your tech skills seperated by comma. ex)react,node
textarea(name="tech", id="tech", placeholder="Add Tech you can use")=user.tech
label(for="career") Enter your careers seperated by comma. ex)A company, B competition
textarea(name="career", id="career", placeholder="Add your Career")=user.career
label(for="introduction") Self introduction
textarea(name="introduction", id="introduction", placeholder="Self introduction", maxlength=200)=user.introduction
input(type="submit", value="Update Profile")
\ No newline at end of file
...
...
src/views/home.pug
View file @
dc5bc26
...
...
@@ -7,7 +7,11 @@ block content
h1 -Developer Profile-
h2=quote
h3=author
if !loggedUser
.home-link
a(href="/join") Join
|#{' '}
a(href="/login") Login
else
a(href=`/users/${loggedUser._id}`) My profile
\ No newline at end of file
...
...
src/views/join.pug
View file @
dc5bc26
...
...
@@ -3,10 +3,9 @@ extends layouts/main
block content
i.fas.fa-location-arrow
h3 Start with GitHub!
button.login-github
a(href="/auth/github")
span
.login-github
i.fab.fa-github
|
Join with GitHub
span
Join with GitHub
\ No newline at end of file
...
...
src/views/login.pug
View file @
dc5bc26
...
...
@@ -3,10 +3,9 @@ extends layouts/main
block content
i.fas.fa-location-arrow
h3 Login with GitHub!
button.login-github
a(href="/auth/github")
span
.login-github
i.fab.fa-github
|
Login with GitHub
span
Login with GitHub
\ No newline at end of file
...
...
src/views/partials/footer.pug
View file @
dc5bc26
footer.footer
hr
.footer__icon
i.fas.fa-code-branch
span.footer__text © dev-profile #{new Date().getFullYear()}
\ No newline at end of file
...
...
src/views/partials/header.pug
View file @
dc5bc26
...
...
@@ -14,6 +14,8 @@ header.header
li
a(href="/") Home
li
a(href=`/users/${loggedUser._id}`) My Profile
li
a(href="/users/edit-profile") Edit Profile
li
a(href="/logout") Log Out
\ No newline at end of file
...
...
Please
register
or
login
to post a comment