Showing
4 changed files
with
146 additions
and
65 deletions
| ... | @@ -11,6 +11,7 @@ KHU-Hub repo: [khuhub.khu.ac.kr/2018102216/dev-profile](https://khuhub.khu.ac.kr | ... | @@ -11,6 +11,7 @@ KHU-Hub repo: [khuhub.khu.ac.kr/2018102216/dev-profile](https://khuhub.khu.ac.kr |
| 11 | - [x] random quotes **_for developers_** to motivate you :sparkles: | 11 | - [x] random quotes **_for developers_** to motivate you :sparkles: |
| 12 | - [ ] the amount of commits you've done on [GitHub](https://github.com/) at a glance | 12 | - [ ] the amount of commits you've done on [GitHub](https://github.com/) at a glance |
| 13 | - [ ] your most-contributed project on GitHub | 13 | - [ ] your most-contributed project on GitHub |
| 14 | +- [x] today's trending repositories on GitHub | ||
| 14 | <br> | 15 | <br> |
| 15 | 16 | ||
| 16 | ### Additional Features | 17 | ### Additional Features | ... | ... |
| ... | @@ -2,80 +2,144 @@ import axios from "axios"; | ... | @@ -2,80 +2,144 @@ import axios from "axios"; |
| 2 | import passport from "passport"; | 2 | import passport from "passport"; |
| 3 | import User from "../models/User"; | 3 | import User from "../models/User"; |
| 4 | 4 | ||
| 5 | -const getQuote = async (req,res) =>{ | 5 | +const getQuote = async (req, res) => { |
| 6 | - const url = "http://quotes.stormconsultancy.co.uk/random.json"; | 6 | + const url = "http://quotes.stormconsultancy.co.uk/random.json"; |
| 7 | - const quoteData = await axios.get(url).then(function(response){ | 7 | + const quoteData = await axios.get(url).then(function (response) { |
| 8 | - return response.data; | 8 | + return response.data; |
| 9 | - }); | 9 | + }); |
| 10 | - const quote = quoteData.quote; | 10 | + const quote = quoteData.quote; |
| 11 | - const author = quoteData.author; | 11 | + const author = quoteData.author; |
| 12 | - return {quote,author}; | 12 | + return { quote, author }; |
| 13 | -} | 13 | +}; |
| 14 | - | ||
| 15 | -export const handleHome = async (req,res)=>{ | ||
| 16 | - const quote = await getQuote(); | ||
| 17 | - res.render("home",{pageTitle:"Home", quote:quote.quote, author:quote.author}); | ||
| 18 | -} | ||
| 19 | 14 | ||
| 15 | +const gitTrend = async (req, res) => { | ||
| 16 | + const url = | ||
| 17 | + "https://api.trending-github.com/github/repositories?period=daily"; | ||
| 18 | + const trendData = await axios.get(url).then(function (response) { | ||
| 19 | + return response.data; | ||
| 20 | + }); | ||
| 21 | + const name0 = trendData[0].name; | ||
| 22 | + const description0 = trendData[0].description; | ||
| 23 | + const Url0 = trendData[0].url; | ||
| 24 | + const stars0 = trendData[0].stars; | ||
| 25 | + const name1 = trendData[1].name; | ||
| 26 | + const description1 = trendData[1].description; | ||
| 27 | + const Url1 = trendData[1].url; | ||
| 28 | + const stars1 = trendData[1].stars; | ||
| 29 | + const name2 = trendData[2].name; | ||
| 30 | + const description2 = trendData[2].description; | ||
| 31 | + const Url2 = trendData[2].url; | ||
| 32 | + const stars2 = trendData[2].stars; | ||
| 20 | 33 | ||
| 21 | -export const getUserDetail = async (req,res) =>{ | 34 | + return { |
| 22 | - const quote = await getQuote(); | 35 | + name0, |
| 23 | - res.render("userDetail",{pagetTitle:"User Detail", quote:quote.quote, author:quote.author}) | 36 | + description0, |
| 24 | -} | 37 | + Url0, |
| 38 | + stars0, | ||
| 39 | + name1, | ||
| 40 | + description1, | ||
| 41 | + Url1, | ||
| 42 | + stars1, | ||
| 43 | + name2, | ||
| 44 | + description2, | ||
| 45 | + Url2, | ||
| 46 | + stars2, | ||
| 47 | + }; | ||
| 48 | +}; | ||
| 25 | 49 | ||
| 26 | -export const getEditProfile = (req,res)=> res.render("editProfile",{pageTitle:"Edit Profile"}); | 50 | +export const handleHome = async (req, res) => { |
| 51 | + const quote = await getQuote(); | ||
| 52 | + const trend = await gitTrend(); | ||
| 53 | + res.render("home", { | ||
| 54 | + pageTitle: "Home", | ||
| 55 | + quote: quote.quote, | ||
| 56 | + author: quote.author, | ||
| 57 | + name0: trend.name0, | ||
| 58 | + description0: trend.description0, | ||
| 59 | + Url0: trend.Url0, | ||
| 60 | + stars0: trend.stars0, | ||
| 61 | + name1: trend.name1, | ||
| 62 | + description1: trend.description1, | ||
| 63 | + Url1: trend.Url1, | ||
| 64 | + stars1: trend.stars1, | ||
| 65 | + name2: trend.name2, | ||
| 66 | + description2: trend.description2, | ||
| 67 | + Url2: trend.Url2, | ||
| 68 | + stars2: trend.stars2, | ||
| 69 | + }); | ||
| 70 | +}; | ||
| 27 | 71 | ||
| 28 | -export const postEditProfile = (req,res) =>{ | 72 | +export const getUserDetail = async (req, res) => { |
| 29 | - console.log(req.body); | 73 | + const quote = await getQuote(); |
| 30 | - res.redirect("/users/edit-profile"); | 74 | + res.render("userDetail", { |
| 75 | + pagetTitle: "User Detail", | ||
| 76 | + quote: quote.quote, | ||
| 77 | + author: quote.author, | ||
| 78 | + }); | ||
| 31 | }; | 79 | }; |
| 32 | 80 | ||
| 81 | +export const getEditProfile = (req, res) => | ||
| 82 | + res.render("editProfile", { pageTitle: "Edit Profile" }); | ||
| 33 | 83 | ||
| 34 | -export const getJoin = (req,res)=>{ | 84 | +export const postEditProfile = (req, res) => { |
| 35 | - res.render("join",{pageTitle: "Join"}); | 85 | + console.log(req.body); |
| 86 | + res.redirect("/users/edit-profile"); | ||
| 36 | }; | 87 | }; |
| 37 | 88 | ||
| 38 | -export const getLogin = (req,res)=>{ | 89 | +export const getJoin = (req, res) => { |
| 39 | - res.render("login",{pageTitle: "Login"}); | 90 | + res.render("join", { pageTitle: "Join" }); |
| 40 | }; | 91 | }; |
| 41 | 92 | ||
| 42 | -export const handleUsers = (req,res)=>{ | 93 | +export const getLogin = (req, res) => { |
| 43 | - res.render("users",{pageTitle:"Users"}); | 94 | + res.render("login", { pageTitle: "Login" }); |
| 44 | -} | 95 | +}; |
| 45 | 96 | ||
| 46 | -export const githubLogin = passport.authenticate("github", {scope: [ "user:email" ]}); | 97 | +export const handleUsers = (req, res) => { |
| 98 | + res.render("users", { pageTitle: "Users" }); | ||
| 99 | +}; | ||
| 100 | + | ||
| 101 | +export const githubLogin = passport.authenticate("github", { | ||
| 102 | + scope: ["user:email"], | ||
| 103 | +}); | ||
| 47 | 104 | ||
| 48 | -export const githubLoginCallback = async (_, __, profile, done) =>{ | 105 | +export const githubLoginCallback = async (_, __, profile, done) => { |
| 49 | - const {_json: {id:githubId, login:githubName, avatar_url:avatarUrl, name, email}} = profile; | 106 | + const { |
| 107 | + _json: { | ||
| 108 | + id: githubId, | ||
| 109 | + login: githubName, | ||
| 110 | + avatar_url: avatarUrl, | ||
| 111 | + name, | ||
| 112 | + email, | ||
| 113 | + }, | ||
| 114 | + } = profile; | ||
| 50 | 115 | ||
| 51 | - try{ | 116 | + try { |
| 52 | - const user = await User.findOne({email}); | 117 | + const user = await User.findOne({ email }); |
| 53 | - if(user){ | 118 | + if (user) { |
| 54 | - user.githubId = githubId, | 119 | + (user.githubId = githubId), (user.githubName = githubName); |
| 55 | - user.githubName = githubName | 120 | + await user.save(); |
| 56 | - await user.save(); | 121 | + return done(null, user); |
| 57 | - return done(null, user); | 122 | + } else { |
| 58 | - }else{ | 123 | + const newUser = await User.create({ |
| 59 | - const newUser = await User.create({ | 124 | + githubId, |
| 60 | - githubId, | 125 | + githubName, |
| 61 | - githubName, | 126 | + avatarUrl, |
| 62 | - avatarUrl, | 127 | + name, |
| 63 | - name, | 128 | + email, |
| 64 | 129 | + }); | |
| 65 | - }); | 130 | + return done(null, newUser); |
| 66 | - return done(null, newUser); | ||
| 67 | - } | ||
| 68 | - }catch(error){ | ||
| 69 | - return done(error); | ||
| 70 | } | 131 | } |
| 132 | + } catch (error) { | ||
| 133 | + return done(error); | ||
| 134 | + } | ||
| 71 | }; | 135 | }; |
| 72 | 136 | ||
| 73 | -export const postGithubLogin = (req,res)=>{ | 137 | +export const postGithubLogin = (req, res) => { |
| 74 | - const userId = req.user.id; | 138 | + const userId = req.user.id; |
| 75 | - res.redirect(`/users/${userId}`); | 139 | + res.redirect(`/users/${userId}`); |
| 76 | -} | 140 | +}; |
| 77 | 141 | ||
| 78 | -export const logout = (req,res)=>{ | ||
| 79 | - req.logout(); | ||
| 80 | - res.redirect("/"); | ||
| 81 | -} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 142 | +export const logout = (req, res) => { | ||
| 143 | + req.logout(); | ||
| 144 | + res.redirect("/"); | ||
| 145 | +}; | ... | ... |
| 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 } from "../middlewares"; | 8 | import { onlyPrivate } from "../middlewares"; |
| 4 | 9 | ||
| 5 | - | ||
| 6 | const userRouter = express.Router(); | 10 | const userRouter = express.Router(); |
| 7 | 11 | ||
| 8 | -userRouter.get("/",handleUsers); | 12 | +userRouter.get("/", handleUsers); |
| 9 | 13 | ||
| 10 | userRouter.get("/edit-profile", onlyPrivate, getEditProfile); | 14 | userRouter.get("/edit-profile", onlyPrivate, getEditProfile); |
| 11 | userRouter.post("/edit-profile", onlyPrivate, postEditProfile); | 15 | userRouter.post("/edit-profile", onlyPrivate, postEditProfile); |
| 12 | 16 | ||
| 13 | userRouter.get("/:id", getUserDetail); | 17 | userRouter.get("/:id", getUserDetail); |
| 14 | 18 | ||
| 15 | - | ||
| 16 | -export default userRouter; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 19 | +export default userRouter; | ... | ... |
| ... | @@ -7,7 +7,20 @@ block content | ... | @@ -7,7 +7,20 @@ block content |
| 7 | h1 -Developer Profile- | 7 | h1 -Developer Profile- |
| 8 | h2=quote | 8 | h2=quote |
| 9 | h3=author | 9 | h3=author |
| 10 | + | ||
| 11 | + button.gotoTrend(style='background-color: white;') | ||
| 12 | + p(style='color: orange;') Trending Repositories: | ||
| 13 | + br | ||
| 14 | + a(href=Url0, style={color:'grey'}) | ||
| 15 | + p=name0+": "+description0+" - "+stars0+" stars" | ||
| 16 | + a(href=Url1, style={color:'grey'}) | ||
| 17 | + p=name1+": "+description1+" - "+stars1+" stars" | ||
| 18 | + a(href=Url2, style={color:'grey'}) | ||
| 19 | + p=name2+": "+description2+" - "+stars2+" stars" | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 10 | .home-link | 23 | .home-link |
| 11 | a(href="/join") Join | 24 | a(href="/join") Join |
| 12 | |#{' '} | 25 | |#{' '} |
| 13 | - a(href="/login") Login | 26 | + a(href="/login") Login |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment