Showing
8 changed files
with
97 additions
and
25 deletions
jaksimsamil-page/.eslintcache
0 → 100644
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
| 1 | import { makeStyles } from '@material-ui/core/styles'; | 1 | import { makeStyles } from '@material-ui/core/styles'; |
| 2 | import TextField from '@material-ui/core/TextField'; | 2 | import TextField from '@material-ui/core/TextField'; |
| 3 | import React from 'react'; | 3 | import React from 'react'; |
| 4 | -import path from 'path'; | 4 | +import getRecommend from "../../scripts/getRecommend"; |
| 5 | -require("dotenv").config({ | ||
| 6 | - path : path.join(__dirname,'/jaksimsamil-server/.env') | ||
| 7 | -}); | ||
| 8 | -console.log(process.env.KAKAO_JS_KEY); | ||
| 9 | - | ||
| 10 | -const useStyles = makeStyles((theme) => ({ | ||
| 11 | - root: { | ||
| 12 | - '& > *': { | ||
| 13 | - margin: theme.spacing(1), | ||
| 14 | - }, | ||
| 15 | - }, | ||
| 16 | - button: { | ||
| 17 | - margin: theme.spacing(1), | ||
| 18 | - }, | ||
| 19 | -})); | ||
| 20 | 5 | ||
| 21 | const KakaoLoginBtn = () => { | 6 | const KakaoLoginBtn = () => { |
| 22 | - const classes = useStyles(); | 7 | + const KakaoLogin = function () { |
| 23 | - const kakaoLogin = function() { | ||
| 24 | window.Kakao.Auth.login({ | 8 | window.Kakao.Auth.login({ |
| 25 | - success:function(auth) { | 9 | + success: getRecommend, |
| 26 | - console.log(auth); | 10 | + fail: function (err) { |
| 27 | - }, | 11 | + console.log("login failed", err); |
| 28 | - fail:function(err) { | ||
| 29 | - console.log(err); | ||
| 30 | } | 12 | } |
| 31 | }) | 13 | }) |
| 32 | } | 14 | } |
| 33 | return ( | 15 | return ( |
| 34 | <div> | 16 | <div> |
| 35 | - <button onClick={kakaoLogin}>KakaoLogin</button> | 17 | + <button onClick={KakaoLogin} |
| 18 | + a id="custom-login-btn" href="javascript:loginWithKakao()"> | ||
| 19 | + <img | ||
| 20 | + src="//k.kakaocdn.net/14/dn/btqCn0WEmI3/nijroPfbpCa4at5EIsjyf0/o.jpg" | ||
| 21 | + width="140" | ||
| 22 | + /> | ||
| 23 | + </button> | ||
| 36 | </div> | 24 | </div> |
| 37 | ); | 25 | ); |
| 38 | }; | 26 | }; | ... | ... |
| ... | @@ -9,3 +9,8 @@ export const register = ({ username, password }) => | ... | @@ -9,3 +9,8 @@ export const register = ({ username, password }) => |
| 9 | export const check = () => client.get('api/auth/check'); | 9 | export const check = () => client.get('api/auth/check'); |
| 10 | 10 | ||
| 11 | export const logout = () => client.post('/api/auth/logout'); | 11 | export const logout = () => client.post('/api/auth/logout'); |
| 12 | + | ||
| 13 | +export const kakaotoken = (kakaotoken) => | ||
| 14 | + client.post('api/auth/kakaotoken', { | ||
| 15 | + kakaotoken: kakaotoken | ||
| 16 | + }); | ... | ... |
jaksimsamil-page/src/scripts/getRecommend.js
0 → 100644
| 1 | +function getRecommend(auth) { | ||
| 2 | + console.log("login success", auth); | ||
| 3 | + const host = 'http://localhost:23023'; | ||
| 4 | + const url = host+"/api/profile/recommend"; | ||
| 5 | + const data = { username: 'test' }; | ||
| 6 | + window.fetch(url, { | ||
| 7 | + method: "POST", | ||
| 8 | + body: JSON.stringify(data), | ||
| 9 | + headers: { | ||
| 10 | + 'Content-Type': 'application/json' | ||
| 11 | + } | ||
| 12 | + }) | ||
| 13 | + .then(res => { | ||
| 14 | + console.log(res); | ||
| 15 | + return res.json(); | ||
| 16 | + }) | ||
| 17 | + .then(shareToKakao); | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +function shareToKakao({problem_number, problem_title, solved_date}) { | ||
| 21 | + console.log('getting ready to share...'); | ||
| 22 | + const boj_link = "https://acmicpc.net/problem/" + problem_number.toString(); | ||
| 23 | + window.Kakao.Link.sendDefault({ | ||
| 24 | + objectType: 'text', | ||
| 25 | + text: `오늘의 추천문제는 ${problem_title}`, | ||
| 26 | + link: { | ||
| 27 | + mobileWebUrl: boj_link, | ||
| 28 | + webUrl: boj_link, | ||
| 29 | + } | ||
| 30 | + }); | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +export { | ||
| 34 | + getRecommend as default | ||
| 35 | +}; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | const Router = require("koa-router"); | 1 | const Router = require("koa-router"); |
| 2 | const auth = new Router(); | 2 | const auth = new Router(); |
| 3 | const authCtrl = require("./auth.ctrl"); | 3 | const authCtrl = require("./auth.ctrl"); |
| 4 | +const kakaoAuth = require("./kakaoAuth"); | ||
| 5 | + | ||
| 4 | auth.post("/login", authCtrl.login); | 6 | auth.post("/login", authCtrl.login); |
| 5 | auth.post("/logout", authCtrl.logout); | 7 | auth.post("/logout", authCtrl.logout); |
| 6 | auth.post("/register", authCtrl.register); | 8 | auth.post("/register", authCtrl.register); |
| 7 | auth.get("/check", authCtrl.check); | 9 | auth.get("/check", authCtrl.check); |
| 8 | 10 | ||
| 11 | +auth.post("/kakaotoken", kakaoAuth.kakaotoken); | ||
| 12 | + | ||
| 9 | module.exports = auth; | 13 | module.exports = auth; | ... | ... |
jaksimsamil-server/src/api/auth/kakaoAuth.js
0 → 100644
| 1 | +const request = require('request'); | ||
| 2 | +const querystring = require('querystring'); | ||
| 3 | + | ||
| 4 | + | ||
| 5 | +exports.kakaotoken = async (ctx) => { | ||
| 6 | + const token = ctx.request.body; | ||
| 7 | + | ||
| 8 | + 'http://kapi.kakao.com/v2/api/talk/memo/default/send' | ||
| 9 | + | ||
| 10 | + console.log(ctx); | ||
| 11 | + console.log("token setted", token); | ||
| 12 | + let template_objectObj = { | ||
| 13 | + object_type: "text", | ||
| 14 | + text: "hi", link: { | ||
| 15 | + web_url: "https://developers.kakao.com", | ||
| 16 | + } | ||
| 17 | + }; | ||
| 18 | + | ||
| 19 | + let template_objectStr = JSON.stringify(template_objectObj); | ||
| 20 | + console.log(template_objectStr); | ||
| 21 | + let options = { | ||
| 22 | + url: "http://kapi.kakao.com/v2/api/talk/memo/default/send", | ||
| 23 | + method: "POST", | ||
| 24 | + headers: { | ||
| 25 | + "Authorization": "Bearer ".concat(token), | ||
| 26 | + "Content-Type": "application/x-www-form-urlencoded" | ||
| 27 | + }, form: { | ||
| 28 | + template_object: template_objectStr | ||
| 29 | + } | ||
| 30 | + }; | ||
| 31 | + request.post(options, (err, res, body) => { | ||
| 32 | + if (err != null) { | ||
| 33 | + console.log(err); | ||
| 34 | + } | ||
| 35 | + }); | ||
| 36 | +}; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -118,14 +118,16 @@ POST /api/proflie/recommend | ... | @@ -118,14 +118,16 @@ POST /api/proflie/recommend |
| 118 | */ | 118 | */ |
| 119 | exports.recommend = async (ctx) => { | 119 | exports.recommend = async (ctx) => { |
| 120 | const { username } = ctx.request.body; | 120 | const { username } = ctx.request.body; |
| 121 | - | ||
| 122 | if (!username) { | 121 | if (!username) { |
| 122 | + console.log('no given username'); | ||
| 123 | ctx.status = 401; | 123 | ctx.status = 401; |
| 124 | return; | 124 | return; |
| 125 | } | 125 | } |
| 126 | try { | 126 | try { |
| 127 | + console.log('finding username:', username); | ||
| 127 | const profile = await Profile.findByUsername(username); | 128 | const profile = await Profile.findByUsername(username); |
| 128 | if (!profile) { | 129 | if (!profile) { |
| 130 | + console.log('no profile'); | ||
| 129 | ctx.status = 401; | 131 | ctx.status = 401; |
| 130 | return; | 132 | return; |
| 131 | } | 133 | } |
| ... | @@ -137,5 +139,7 @@ exports.recommend = async (ctx) => { | ... | @@ -137,5 +139,7 @@ exports.recommend = async (ctx) => { |
| 137 | //데이터가 비었을 떄 예외처리 필요 | 139 | //데이터가 비었을 떄 예외처리 필요 |
| 138 | } catch (e) { | 140 | } catch (e) { |
| 139 | ctx.throw(500, e); | 141 | ctx.throw(500, e); |
| 142 | + } finally { | ||
| 143 | + console.log('successfully sent user recommendation') | ||
| 140 | } | 144 | } |
| 141 | }; | 145 | }; | ... | ... |
-
Please register or login to post a comment