Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021_dev-profile
/
dev-profile
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
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
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
91 additions
and
52 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,37 +71,44 @@ 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
}
export
const
getEditProfile
=
async
(
req
,
res
)
=>
{
const
{
user
:
{
_id
:
id
},
}
=
req
;
try
{
try
{
const
user
=
await
User
.
findById
(
id
);
if
(
user
.
id
!==
id
)
{
if
(
user
.
id
!==
id
)
{
throw
Error
();
}
else
{
res
.
render
(
"editProfile"
,{
pageTitle
:
"Edit Profile"
,
user
});
}
else
{
res
.
render
(
"editProfile"
,
{
pageTitle
:
"Edit Profile"
,
user
});
}
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
);
}
};
export
const
postEditProfile
=
async
(
req
,
res
)
=>
{
export
const
postEditProfile
=
async
(
req
,
res
)
=>
{
const
{
user
:{
_id
:
id
},
body
:
{
name
,
email
,
school
,
blogUrl
,
tech
,
career
,
introduction
},
file
user
:
{
_id
:
id
},
body
:
{
name
,
email
,
school
,
blogUrl
,
tech
,
career
,
introduction
},
file
,
}
=
req
;
try
{
const
updatedUser
=
await
User
.
findByIdAndUpdate
(
id
,
{
try
{
const
updatedUser
=
await
User
.
findByIdAndUpdate
(
id
,
{
avatarUrl
:
file
?
file
.
path
:
req
.
session
.
passport
.
user
.
avatarUrl
,
name
,
email
,
...
...
@@ -111,14 +116,16 @@ export const postEditProfile = async (req,res) =>{
blogUrl
,
tech
:
User
.
formatTech
(
tech
),
career
:
User
.
formatCareer
(
career
),
introduction
introduction
,
},
{
new
:
true
});
new
:
true
,
}
);
req
.
session
.
passport
.
user
=
updatedUser
;
//console.log(updatedUser);
res
.
redirect
(
"/users/edit-profile"
);
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
);
res
.
redirect
(
"/"
);
}
...
...
@@ -151,24 +158,23 @@ export const githubLoginCallback = async (_, __, profile, done) => {
},
}
=
profile
;
try
{
const
user
=
await
User
.
findOne
({
githubId
});
if
(
user
){
user
.
githubId
=
githubId
,
user
.
githubName
=
githubName
try
{
const
user
=
await
User
.
findOne
({
githubId
});
if
(
user
)
{
(
user
.
githubId
=
githubId
),
(
user
.
githubName
=
githubName
);
await
user
.
save
();
return
done
(
null
,
user
);
}
else
{
}
else
{
const
newUser
=
await
User
.
create
({
githubId
,
githubName
,
avatarUrl
,
name
,
email
email
,
});
return
done
(
null
,
newUser
);
}
}
catch
(
error
)
{
}
catch
(
error
)
{
return
done
(
error
);
}
};
...
...
src/models/User.js
View file @
d3895d4
...
...
@@ -3,53 +3,52 @@ import mongoose from "mongoose";
const
UserSchema
=
new
mongoose
.
Schema
({
name
:
{
type
:
String
,
trim
:
true
trim
:
true
,
},
email
:
{
type
:
String
,
trim
:
true
,
unique
:
true
unique
:
true
,
},
avatarUrl
:
String
,
githubId
:
{
type
:
Number
,
required
:
"GitHub id
is required"
,
unique
:
true
required
:
"GitHub ID
is required"
,
unique
:
true
,
},
githubName
:
{
type
:
String
,
required
:
"Github nickname is required"
,
trim
:
true
trim
:
true
,
},
school
:
{
type
:
String
,
trim
:
true
trim
:
true
,
},
tech
:
[{
type
:
String
,
trim
:
true
}],
career
:
[{
type
:
String
,
trim
:
true
}],
introduction
:
{
type
:
String
,
maxLength
:
500
},
introduction
:
{
type
:
String
,
maxLength
:
500
},
createdAt
:
{
type
:
Date
,
default
:
Date
.
now
default
:
Date
.
now
,
},
blogUrl
:
{
type
:
String
,
default
:
"#"
default
:
"#"
,
},
githubUrl
:
{
type
:
String
,
default
:
"#"
}
default
:
"#"
,
},
});
UserSchema
.
static
(
"formatTech"
,
function
(
tech
)
{
UserSchema
.
static
(
"formatTech"
,
function
(
tech
)
{
return
tech
.
split
(
","
);
});
UserSchema
.
static
(
"formatCareer"
,
function
(
career
)
{
UserSchema
.
static
(
"formatCareer"
,
function
(
career
)
{
return
career
.
split
(
","
);
});
const
User
=
mongoose
.
model
(
"User"
,
UserSchema
);
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
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
...
...
Please
register
or
login
to post a comment