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
이세진
2021-05-26 12:50:30 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
d3895d449f6c54e440f3eda651f1e7b94bdfa382
d3895d44
2 parents
29aa8401
78daa54b
Merge branch 'cher' into 'master'
user detail update and more See merge request
!8
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
156 additions
and
117 deletions
README.md
src/controllers/userController.js
src/models/User.js
src/routers/userRouter.js
src/views/home.pug
src/views/userDetail.pug
README.md
View file @
d3895d4
...
...
@@ -37,8 +37,14 @@ npm run dev:server
```
<br>
### API reference
[
Programming Quotes API
](
quotes.stormconsultancy.co.uk/random.json
)
<br>
[
Trending-GitHub API
](
https://docs.trending-github.com/
)
### License
[
MIT
](
https://choosealicense.com/licenses/mit/
)
...
...
src/controllers/userController.js
View file @
d3895d4
...
...
@@ -47,8 +47,6 @@ const gitTrend = async (req, res) => {
};
};
export
const
handleHome
=
async
(
req
,
res
)
=>
{
const
quote
=
await
getQuote
();
const
trend
=
await
gitTrend
();
...
...
@@ -73,55 +71,64 @@ export const handleHome = async (req, res) => {
export
const
getUserDetail
=
async
(
req
,
res
)
=>
{
const
quote
=
await
getQuote
();
const
id
=
req
.
params
.
id
;
const
user
=
await
User
.
findById
(
id
);
console
.
log
(
user
.
tech
);
res
.
render
(
"userDetail"
,
{
pagetTitle
:
"User Detail"
,
quote
:
quote
.
quote
,
author
:
quote
.
author
,
user
,
});
};
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
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
=
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
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
;
//console.log(updatedUser);
res
.
redirect
(
"/users/edit-profile"
);
}
catch
(
error
)
{
console
.
log
(
error
);
res
.
redirect
(
"/"
);
}
};
export
const
getJoin
=
(
req
,
res
)
=>
{
...
...
@@ -151,26 +158,25 @@ export const githubLoginCallback = async (_, __, profile, done) => {
},
}
=
profile
;
try
{
const
user
=
await
User
.
findOne
({
githubId
});
if
(
user
){
user
.
githubId
=
githubId
,
user
.
githubName
=
githubName
await
user
.
save
();
return
done
(
null
,
user
);
}
else
{
const
newUser
=
await
User
.
create
({
githubId
,
githubName
,
avatarUrl
,
name
,
email
});
return
done
(
null
,
newUser
);
}
}
catch
(
error
){
return
done
(
error
);
try
{
const
user
=
await
User
.
findOne
({
githubId
});
if
(
user
)
{
(
user
.
githubId
=
githubId
),
(
user
.
githubName
=
githubName
);
await
user
.
save
();
return
done
(
null
,
user
);
}
else
{
const
newUser
=
await
User
.
create
({
githubId
,
githubName
,
avatarUrl
,
name
,
email
,
});
return
done
(
null
,
newUser
);
}
}
catch
(
error
)
{
return
done
(
error
);
}
};
export
const
postGithubLogin
=
(
req
,
res
)
=>
{
...
...
src/models/User.js
View file @
d3895d4
import
mongoose
from
"mongoose"
;
const
UserSchema
=
new
mongoose
.
Schema
({
name
:
{
type
:
String
,
trim
:
true
},
email
:
{
type
:
String
,
trim
:
true
,
unique
:
true
},
avatarUrl
:
String
,
githubId
:
{
type
:
Number
,
required
:
"GitHub id
is required"
,
unique
:
true
},
githubName
:
{
type
:
String
,
required
:
"Github nickname is required"
,
trim
:
true
},
school
:
{
type
:
String
,
trim
:
true
},
tech
:
[{
type
:
String
,
trim
:
true
}],
career
:
[{
type
:
String
,
trim
:
true
}],
introduction
:
{
type
:
String
,
maxLength
:
500
},
createdAt
:
{
type
:
Date
,
default
:
Date
.
now
},
blogUrl
:
{
type
:
String
,
default
:
"#"
},
githubUrl
:
{
type
:
String
,
default
:
"#"
}
name
:
{
type
:
String
,
trim
:
true
,
},
email
:
{
type
:
String
,
trim
:
true
,
unique
:
true
,
},
avatarUrl
:
String
,
githubId
:
{
type
:
Number
,
required
:
"GitHub ID
is required"
,
unique
:
true
,
},
githubName
:
{
type
:
String
,
required
:
"Github nickname is required"
,
trim
:
true
,
},
school
:
{
type
:
String
,
trim
:
true
,
},
tech
:
[{
type
:
String
,
trim
:
true
}],
career
:
[{
type
:
String
,
trim
:
true
}],
introduction
:
{
type
:
String
,
maxLength
:
500
},
createdAt
:
{
type
:
Date
,
default
:
Date
.
now
,
},
blogUrl
:
{
type
:
String
,
default
:
"#"
,
},
githubUrl
:
{
type
:
String
,
default
:
"#"
,
},
});
UserSchema
.
static
(
"formatTech"
,
function
(
tech
)
{
return
tech
.
split
(
","
);
UserSchema
.
static
(
"formatTech"
,
function
(
tech
)
{
return
tech
.
split
(
","
);
});
UserSchema
.
static
(
"formatCareer"
,
function
(
career
)
{
return
career
.
split
(
","
);
UserSchema
.
static
(
"formatCareer"
,
function
(
career
)
{
return
career
.
split
(
","
);
});
const
User
=
mongoose
.
model
(
"User"
,
UserSchema
);
export
default
User
;
\ No newline at end of file
export
default
User
;
...
...
src/routers/userRouter.js
View file @
d3895d4
import
express
from
"express"
;
import
{
getEditProfile
,
getUserDetail
,
handleUsers
,
postEditProfile
}
from
"../controllers/userController"
;
import
{
getEditProfile
,
getUserDetail
,
handleUsers
,
postEditProfile
,
}
from
"../controllers/userController"
;
import
{
onlyPrivate
,
uploadFiles
}
from
"../middlewares"
;
const
userRouter
=
express
.
Router
();
...
...
@@ -7,7 +12,12 @@ const userRouter = express.Router();
userRouter
.
get
(
"/"
,
handleUsers
);
userRouter
.
get
(
"/edit-profile"
,
onlyPrivate
,
getEditProfile
);
userRouter
.
post
(
"/edit-profile"
,
onlyPrivate
,
uploadFiles
.
single
(
"photo"
),
postEditProfile
);
userRouter
.
post
(
"/edit-profile"
,
onlyPrivate
,
uploadFiles
.
single
(
"photo"
),
postEditProfile
);
userRouter
.
get
(
"/:id"
,
getUserDetail
);
...
...
src/views/home.pug
View file @
d3895d4
...
...
@@ -16,7 +16,7 @@ block content
else
a(href=`/users/${loggedUser._id}`) My profile
.gotoTrend(style="border: 1px solid blue;")
.gotoTrend(style="border: 1px solid blue;")
p(style='color: orange;') Trending Repositories:
br
a(href=Url0, style={color:'grey'})
...
...
src/views/userDetail.pug
View file @
d3895d4
...
...
@@ -11,23 +11,41 @@ block content
img(src="#")
.user-profile__link
a(href="#") Github
|#{' '}
a(href="#") Blog
.user-profile__column
.user-profile__info
h3 NAME
h3 GITHUB NICKNAME
h3 EMAIL
h3 SCHOOL
h3 TECH
h3 CAREER
h3 SELF-INTRODUCTION
h3(style="display: inline;") NAME:
h4(style="display: inline;")=user.name
br
h3(style="display: inline;") GITHUB NICKNAME:
h4(style="display: inline;")=user.githubName
br
h3(style="display: inline;") EMAIL:
h4(style="display: inline;")=user.email
br
h3(style="display: inline;") SCHOOL:
h4(style="display: inline;")=user.school
h3 TECH:
ul
each tech in user.tech
li=tech
h3 CAREER:
ul
each career in user.career
li=career
h3(style="display: inline;") SELF-INTRODUCTION:
h4(style="display: inline;")=user.introduction
hr
.user-status
.user-status__contributions
img(src=
"http://ghchart.rshah.org/lsj8706"
alt="Name Your Github chart")
img(src=
`http://ghchart.rshah.org/${user.githubName}`
alt="Name Your Github chart")
.user-status__character
h3 Your step | commit numbers
img(src="https://preview.free3d.com/img/2019/12/2269306250288170045/1oe8ymrc-900.jpg" alt="character" style="height:200px; width:250px;")
.user-repositories
.user-repo
h3 REPO 1
\ No newline at end of file
h3 REPO 1
\ No newline at end of file
...
...
Please
register
or
login
to post a comment