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
JungSeungHyun
2021-05-25 22:49:59 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
7722c6b0c3e4e588ae58b7b9350240676f567d5e
7722c6b0
2 parents
3df7c656
29aa8401
upstream
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
219 additions
and
74 deletions
.gitignore
README.md
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 @
7722c6b
...
...
@@ -117,6 +117,6 @@ dist
.pnp.*
package-lock.json
uploads
/
uploads
static
build
\ No newline at end of file
...
...
README.md
View file @
7722c6b
...
...
@@ -11,6 +11,7 @@ KHU-Hub repo: [khuhub.khu.ac.kr/2018102216/dev-profile](https://khuhub.khu.ac.kr
-
[
x
]
random quotes
**_for developers_**
to motivate you :sparkles:
-
[
]
the amount of commits you've done on
[
GitHub
](
https://github.com/
)
at a glance
-
[
]
your most-contributed project on GitHub
-
[
x
]
today's trending repositories on GitHub
<br>
### Additional Features
...
...
package.json
View file @
7722c6b
...
...
@@ -23,6 +23,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 @
7722c6b
...
...
@@ -2,54 +2,157 @@ import axios from "axios";
import
passport
from
"passport"
;
import
User
from
"../models/User"
;
const
getQuote
=
async
(
req
,
res
)
=>
{
const
url
=
"http://quotes.stormconsultancy.co.uk/random.json"
;
const
quoteData
=
await
axios
.
get
(
url
).
then
(
function
(
response
)
{
return
response
.
data
;
});
const
quote
=
quoteData
.
quote
;
const
author
=
quoteData
.
author
;
return
{
quote
,
author
};
}
const
getQuote
=
async
(
req
,
res
)
=>
{
const
url
=
"http://quotes.stormconsultancy.co.uk/random.json"
;
const
quoteData
=
await
axios
.
get
(
url
).
then
(
function
(
response
)
{
return
response
.
data
;
});
const
quote
=
quoteData
.
quote
;
const
author
=
quoteData
.
author
;
return
{
quote
,
author
};
}
;
export
const
handleHome
=
async
(
req
,
res
)
=>
{
const
quote
=
await
getQuote
();
res
.
render
(
"home"
,{
pageTitle
:
"Home"
,
quote
:
quote
.
quote
,
author
:
quote
.
author
});
}
const
gitTrend
=
async
(
req
,
res
)
=>
{
const
url
=
"https://api.trending-github.com/github/repositories?period=daily"
;
const
trendData
=
await
axios
.
get
(
url
).
then
(
function
(
response
)
{
return
response
.
data
;
});
const
name0
=
trendData
[
0
].
name
;
const
description0
=
trendData
[
0
].
description
;
const
Url0
=
trendData
[
0
].
url
;
const
stars0
=
trendData
[
0
].
stars
;
const
name1
=
trendData
[
1
].
name
;
const
description1
=
trendData
[
1
].
description
;
const
Url1
=
trendData
[
1
].
url
;
const
stars1
=
trendData
[
1
].
stars
;
const
name2
=
trendData
[
2
].
name
;
const
description2
=
trendData
[
2
].
description
;
const
Url2
=
trendData
[
2
].
url
;
const
stars2
=
trendData
[
2
].
stars
;
return
{
name0
,
description0
,
Url0
,
stars0
,
name1
,
description1
,
Url1
,
stars1
,
name2
,
description2
,
Url2
,
stars2
,
};
};
export
const
getUserDetail
=
async
(
req
,
res
)
=>
{
const
quote
=
await
getQuote
();
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
handleHome
=
async
(
req
,
res
)
=>
{
const
quote
=
await
getQuote
();
const
trend
=
await
gitTrend
();
res
.
render
(
"home"
,
{
pageTitle
:
"Home"
,
quote
:
quote
.
quote
,
author
:
quote
.
author
,
name0
:
trend
.
name0
,
description0
:
trend
.
description0
,
Url0
:
trend
.
Url0
,
stars0
:
trend
.
stars0
,
name1
:
trend
.
name1
,
description1
:
trend
.
description1
,
Url1
:
trend
.
Url1
,
stars1
:
trend
.
stars1
,
name2
:
trend
.
name2
,
description2
:
trend
.
description2
,
Url2
:
trend
.
Url2
,
stars2
:
trend
.
stars2
,
});
};
export
const
postEditProfile
=
(
req
,
res
)
=>
{
console
.
log
(
req
.
body
);
res
.
redirect
(
"/users/edit-profile"
);
export
const
getUserDetail
=
async
(
req
,
res
)
=>
{
const
quote
=
await
getQuote
();
res
.
render
(
"userDetail"
,
{
pagetTitle
:
"User Detail"
,
quote
:
quote
.
quote
,
author
:
quote
.
author
,
});
};
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
getJoin
=
(
req
,
res
)
=>
{
res
.
render
(
"join"
,{
pageTitle
:
"Join"
});
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
(
"/"
);
}
};
export
const
get
Login
=
(
req
,
res
)
=>
{
res
.
render
(
"login"
,{
pageTitle
:
"Login"
});
export
const
get
Join
=
(
req
,
res
)
=>
{
res
.
render
(
"join"
,
{
pageTitle
:
"Join"
});
};
export
const
handleUsers
=
(
req
,
res
)
=>
{
res
.
render
(
"users"
,{
pageTitle
:
"Users"
});
}
export
const
getLogin
=
(
req
,
res
)
=>
{
res
.
render
(
"login"
,
{
pageTitle
:
"Login"
});
}
;
export
const
githubLogin
=
passport
.
authenticate
(
"github"
,
{
scope
:
[
"user:email"
]});
export
const
handleUsers
=
(
req
,
res
)
=>
{
res
.
render
(
"users"
,
{
pageTitle
:
"Users"
});
};
export
const
githubLoginCallback
=
async
(
_
,
__
,
profile
,
done
)
=>
{
const
{
_json
:
{
id
:
githubId
,
login
:
githubName
,
avatar_url
:
avatarUrl
,
name
,
email
}}
=
profile
;
export
const
githubLogin
=
passport
.
authenticate
(
"github"
,
{
scope
:
[
"user:email"
],
});
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
...
...
@@ -70,11 +173,12 @@ export const githubLoginCallback = async (_, __, profile, done) =>{
}
};
export
const
postGithubLogin
=
(
req
,
res
)
=>
{
const
userId
=
req
.
user
.
id
;
res
.
redirect
(
`/users/
${
userId
}
`
);
}
export
const
postGithubLogin
=
(
req
,
res
)
=>
{
const
userId
=
req
.
user
.
id
;
res
.
redirect
(
`/users/
${
userId
}
`
);
}
;
<<<<<<<
HEAD
export
const
logout
=
(
req
,
res
)
=>
{
req
.
logout
();
res
.
redirect
(
"/"
);
...
...
@@ -89,4 +193,10 @@ const getRepos = async(req,res) =>{
const
secondRepoName
=
latelyRepos
.[
1
].
name
;
const
firstRepoUrl
=
latelyRepos
.[
0
].
html_url
;
const
secondRepoUrl
=
latelyRepos
.[
1
].
html_url
;
};
\ No newline at end of file
};
=======
export
const
logout
=
(
req
,
res
)
=>
{
req
.
logout
();
res
.
redirect
(
"/"
);
};
>>>>>>>
29
aa84017aef7f3207044abc818143e72cf33907
...
...
src/middlewares.js
View file @
7722c6b
import
multer
from
"multer"
;
export
const
localsMiddleware
=
(
req
,
res
,
next
)
=>
{
res
.
locals
.
siteName
=
"Dev Profile"
;
res
.
locals
.
loggedUser
=
req
.
user
||
null
;
...
...
@@ -19,4 +21,11 @@ export const onlyPrivate = (req, res, next) => {
}
else
{
res
.
redirect
(
"/"
);
}
};
\ No newline at end of file
};
export
const
uploadFiles
=
multer
({
dest
:
"uploads/"
,
limits
:
{
fileSize
:
3000000
}
});
\ No newline at end of file
...
...
src/models/User.js
View file @
7722c6b
...
...
@@ -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 @
7722c6b
...
...
@@ -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 @
7722c6b
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
();
userRouter
.
get
(
"/"
,
handleUsers
);
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
);
export
default
userRouter
;
\ No newline at end of file
export
default
userRouter
;
...
...
src/server.js
View file @
7722c6b
...
...
@@ -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 @
7722c6b
extends layouts/main
block content
.form-container
form(action="/users/edit-profile", method="POST", enctype="application/json")
.form-container
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 @
7722c6b
...
...
@@ -7,7 +7,22 @@ block content
h1 -Developer Profile-
h2=quote
h3=author
.home-link
a(href="/join") Join
|#{' '}
a(href="/login") Login
if !loggedUser
.home-link
a(href="/join") Join
|#{' '}
a(href="/login") Login
else
a(href=`/users/${loggedUser._id}`) My profile
.gotoTrend(style="border: 1px solid blue;")
p(style='color: orange;') Trending Repositories:
br
a(href=Url0, style={color:'grey'})
p=name0+": "+description0+" - "+stars0+" stars"
a(href=Url1, style={color:'grey'})
p=name1+": "+description1+" - "+stars1+" stars"
a(href=Url2, style={color:'grey'})
p=name2+": "+description2+" - "+stars2+" stars"
...
...
src/views/join.pug
View file @
7722c6b
...
...
@@ -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
i.fab.fa-github
|Join with GitHub
a(href="/auth/github")
.login-github
i.fab.fa-github
span Join with GitHub
\ No newline at end of file
...
...
src/views/login.pug
View file @
7722c6b
...
...
@@ -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
i.fab.fa-github
|Login with GitHub
a(href="/auth/github")
.login-github
i.fab.fa-github
span Login with GitHub
\ No newline at end of file
...
...
src/views/partials/footer.pug
View file @
7722c6b
footer.footer
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 @
7722c6b
...
...
@@ -12,7 +12,9 @@ header.header
else
li
a(href="/") Home
a(href="/") Home
li
a(href=`/users/${loggedUser._id}`) My Profile
li
a(href="/users/edit-profile") Edit Profile
li
...
...
Please
register
or
login
to post a comment