code stringlengths 41 34.3k | lang stringclasses 8
values | review stringlengths 1 4.74k |
|---|---|---|
@@ -1,10 +1,178 @@
import React from 'react';
+import Nav from '../../../components/Nav/Nav';
+import Feed from '../../../components/Feed/Feed';
+import './Main.scss';
+
class Main extends React.Component {
+ constructor() {
+ super();
+ this.state = {
+ feeds: [],
+ };
+ }
+
+ componentDidMount() {
+ fetch('/data/feedData.json', {
+ method: 'GET',
+ })
+ .then(res => res.json())
+ .then(data => {
+ this.setState({
+ feeds: data,
+ });
+ });
+ }
+
render() {
+ const { feeds } = this.state;
+
+ const STORIES = [
+ {
+ alt: '์คํ ๋ฆฌ ํ๋กํ ์ฌ์ง',
+ img: '/images/youngho/wecode.png',
+ name: 'wecorder1',
+ time: 43,
+ },
+ {
+ alt: '์คํ ๋ฆฌ ํ๋กํ ์ฌ์ง',
+ img: '/images/youngho/wecode.png',
+ name: 'wecorder2',
+ time: 3,
+ },
+ {
+ alt: '์คํ ๋ฆฌ ํ๋กํ ์ฌ์ง',
+ img: '/images/youngho/wecode.png',
+ name: 'wecorder3',
+ time: 23,
+ },
+ {
+ alt: '์คํ ๋ฆฌ ํ๋กํ ์ฌ์ง',
+ img: '/images/youngho/wecode.png',
+ name: 'wecorder4',
+ time: 27,
+ },
+ {
+ alt: '์คํ ๋ฆฌ ํ๋กํ ์ฌ์ง',
+ img: '/images/youngho/wecode.png',
+ name: 'wecorder5',
+ time: 13,
+ },
+ ];
+
+ const Stories = STORIES.map(store => {
+ return (
+ <div className="story">
+ <img alt={store.alt} src={store.img} />
+ <div>
+ <div className="boldFont">{store.name}</div>
+ <div className="lightFont">{store.time}๋ถ ์ </div>
+ </div>
+ </div>
+ );
+ });
return (
<div>
- <h3>๋ฉ์ธ</h3>
+ <Nav />
+ <main>
+ <div className="content">
+ <div>
+ {feeds.map(feed => {
+ return <Feed key={`feed${feed.id}`} data={feed} />;
+ })}
+ </div>
+ <div className="mainRight">
+ <div className="rightTop">
+ <img
+ className="wecodeLogo"
+ alt="์์ฝ๋ ์ฌ์ง"
+ src="/images/youngho/wecode.png"
+ />
+ <div>
+ <div className="boldFont">wecode_bootcamp</div>
+ <div className="lightFont">WeCode | ์์ฝ๋</div>
+ </div>
+ </div>
+ <div className="rightMiddle">
+ <div className="seeAllStory">
+ <div className="lightFont">์คํ ๋ฆฌ</div>
+ <div className="boldFont">๋ชจ๋ ๋ณด๊ธฐ</div>
+ </div>
+ <div className="seeStory">{Stories}</div>
+ </div>
+ <div className="rightMiddle">
+ <div className="friendsRecommendContainer">
+ <div className="lightFont">ํ์๋์ ์ํ ์ถ์ฒ</div>
+ <div className="boldFont">๋ชจ๋ ๋ณด๊ธฐ</div>
+ </div>
+ <div className="friendsRecommendList">
+ <div className="friendsRecommend">
+ <img
+ alt="์น๊ตฌ์ถ์ฒ ํ๋กํ ์ฌ์ง"
+ src="/images/youngho/wecode.png"
+ />
+ <div>
+ <div className="boldFont">ํ๊ธธ๋</div>
+ <div className="lightFont">๋ธ๋ผ๋ธ๋ผ๋ ์ธ 2๋ช
์ด ...</div>
+ </div>
+ <div className="followFont boldFont">ํ๋ก์ฐ</div>
+ </div>
+ <div className="friendsRecommend">
+ <img
+ alt="์น๊ตฌ์ถ์ฒ ํ๋กํ ์ฌ์ง"
+ src="/images/youngho/wecode.png"
+ />
+ <div>
+ <div className="boldFont">์๋ฌด๊ฐ</div>
+ <div className="lightFont">์๋์๋๋ ์ธ 2๋ช
์ด ...</div>
+ </div>
+ <div className="followFont boldFont">ํ๋ก์ฐ</div>
+ </div>
+ <div className="friendsRecommend">
+ <img
+ alt="์น๊ตฌ์ถ์ฒ ํ๋กํ ์ฌ์ง"
+ src="/images/youngho/wecode.png"
+ />
+ <div>
+ <div className="boldFont">์ด์ฉ๊ตฌ</div>
+ <div className="lightFont">์๋ผ์๋ผ๋ ์ธ 2๋ช
์ด ...</div>
+ </div>
+ <div className="followFont boldFont">ํ๋ก์ฐ</div>
+ </div>
+ <div className="friendsRecommend">
+ <img
+ alt="์น๊ตฌ์ถ์ฒ ํ๋กํ ์ฌ์ง"
+ src="/images/youngho/wecode.png"
+ />
+ <div>
+ <div className="boldFont">์ ์ฉ๊ตฌ</div>
+ <div className="lightFont">์๋ก์๋ก๋ ์ธ 2๋ช
์ด ...</div>
+ </div>
+ <div className="followFont boldFont">ํ๋ก์ฐ</div>
+ </div>
+ <div className="friendsRecommend">
+ <img
+ alt="์น๊ตฌ์ถ์ฒ ํ๋กํ ์ฌ์ง"
+ src="/images/youngho/wecode.png"
+ />
+ <div>
+ <div className="boldFont">์ผ๋ผ์ผ๋ผ</div>
+ <div className="lightFont">๋ธ๋ผ๋ธ๋ผ๋ ์ธ 2๋ช
์ด ...</div>
+ </div>
+ <div className="followFont boldFont">ํ๋ก์ฐ</div>
+ </div>
+ </div>
+ </div>
+ <footer>
+ <div className="lightFont">
+ Westagram ์ ๋ณด . ์ง์ . ํ๋ณด ์ผํฐ . API . ์ฑ์ฉ์ ๋ณด .
+ ๊ฐ์ธ์ ๋ณด์ฒ๋ฆฌ๋ฐฉ์นจ . ์ฝ๊ด . ๋๋ ํฐ๋ฆฌ . ํ๋กํ . ํด์ํ๊ทธ . ์ธ์ด
+ </div>
+ <div className="lightFont boldFont">ยฉ 2021 WESTAGRAM</div>
+ </footer>
+ </div>
+ </div>
+ </main>
</div>
);
} | JavaScript | story ๋ถ๋ถ์ด ์ฌ๋ฌ๋ฒ ๋ฐ๋ณต๋๊ณ ์๋ค์!
์์ ๋ฐ์ดํฐ์ map์ ์ฌ์ฉํด์ ์ค๋ณต๋ ๋ถ๋ถ์ ์ค์ฌ์ฃผ์ธ์!
```
const STORIES = [
{img: "//", name: "wecorder1"}, {img: "//", name: "wecorder2"}, {img: "//", name: "wecorder3"}
];
STORIES.map();
``` |
@@ -0,0 +1,285 @@
+@import 'https://fonts.googleapis.com/css2?family=Lobster&display=swap';
+@media screen and (max-width: 1200px) {
+ .mainRight {
+ display: none;
+ }
+
+ .article {
+ width: 100%;
+ }
+}
+
+body {
+ margin: 0;
+ padding: 0;
+ border-collapse: collapse;
+}
+
+article {
+ width: 800px;
+ background-color: white;
+}
+
+nav {
+ display: flex;
+ justify-content: space-around;
+ align-items: center;
+ margin: 0px 170px;
+ height: 60px;
+}
+
+.logo {
+ width: 30px;
+ height: 30px;
+ padding-right: 15px;
+ border-right: 1px solid black;
+}
+
+.rightIcon {
+ width: 30px;
+ height: 30px;
+ margin-right: 30px;
+}
+
+.instagram {
+ margin-left: 15px;
+ font-family: 'Lobster', cursive;
+ font-size: 33px;
+ font-weight: 1;
+}
+
+.search {
+ outline: none;
+}
+
+.writeComment {
+ width: 100%;
+ height: 40px;
+ padding-left: 10px;
+ border: 1px solid #efefef;
+ outline: none;
+}
+
+.search-box {
+ > input {
+ width: 200px;
+ height: 20px;
+ border: 1px solid #dbdbdb;
+ text-align: center;
+ }
+
+ position: relative;
+ > img {
+ position: absolute;
+ width: 11px;
+ height: 11px;
+ left: 75px;
+ top: 7px;
+ }
+}
+
+main {
+ padding: 60px 0px;
+ background-color: #fafafa;
+}
+
+.content {
+ display: flex;
+ justify-content: space-around;
+ flex-direction: row;
+ margin: 0px 350px;
+}
+
+.mainRight {
+ width: 330px;
+ margin-left: 10px;
+}
+
+.feedTop {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ width: 780px;
+ padding: 10px 10px;
+ border: 1px solid #e6e6e6;
+}
+
+.feedUser {
+ display: flex;
+ align-items: center;
+}
+
+.feedPicture {
+ height: 800px;
+ border: 1px solid #e6e6e6;
+}
+
+.feedId {
+ margin-left: 10px;
+}
+
+.feedMore {
+ width: 15px;
+ height: 15px;
+}
+
+.smallUserPicture {
+ width: 40px;
+ height: 40px;
+ border: 1px solid #e6e6e6;
+ border-radius: 50px;
+}
+
+.feedIcons {
+ > img {
+ width: 27px;
+ height: 27px;
+ }
+
+ > div {
+ > img {
+ width: 27px;
+ height: 27px;
+ }
+ }
+ display: flex;
+ justify-content: space-between;
+ flex-direction: row;
+ margin: 0px;
+}
+
+.feedBottom {
+ padding: 10px 10px;
+ border-left: 1px solid #efefef;
+ border-right: 1px solid #efefef;
+ border-bottom: 1px solid #efefef;
+}
+
+.FeedBottomLeftIcon {
+ > img {
+ padding-right: 10px;
+ }
+}
+
+.like {
+ > img {
+ width: 15px;
+ height: 15px;
+ margin-right: 5px;
+ border: 1px solid #e6e6e6;
+ border-radius: 7px;
+ }
+ display: flex;
+ align-items: center;
+}
+
+.comment {
+ > div {
+ > div {
+ color: #a4a4a4;
+ }
+ }
+}
+
+.commentIcons {
+ float: right;
+ display: inline;
+ width: 15px;
+ height: 15px;
+ margin-left: 5px;
+}
+
+.boldFont {
+ font-weight: bolder;
+}
+
+.addCommentFrom {
+ position: relative;
+ width: 786px;
+}
+
+.postingButton {
+ position: absolute;
+ color: #cde6fc;
+ background-color: white;
+ top: 14px;
+ right: 10px;
+ border: 0;
+ outline: 0;
+}
+
+.rightTop {
+ display: flex;
+ align-items: center;
+ width: 300px;
+}
+
+.wecodeLogo {
+ width: 60px;
+ height: 60px;
+ margin-right: 20px;
+ border-radius: 50px;
+}
+
+.lightFont {
+ color: #9e9e9e;
+}
+
+.followFont {
+ color: #3797f0;
+}
+
+.rightMiddle {
+ height: 200px;
+ margin: 20px 0px;
+ padding: 12px;
+ background: white;
+ border: 3px solid #e6e6e6;
+ border-radius: 7px;
+ overflow: scroll;
+}
+
+.seeAllStory {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+}
+
+.friendsRecommendContainer {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+}
+
+.story {
+ display: flex;
+ align-items: center;
+ margin: 10px;
+
+ > img {
+ width: 40px;
+ height: 40px;
+ margin-right: 10px;
+ border-radius: 50px;
+ border: 2px solid #d93081;
+ }
+}
+
+.friendsRecommend {
+ display: flex;
+ align-items: center;
+ margin: 10px;
+ > img {
+ width: 40px;
+ height: 40px;
+ border-radius: 50px;
+ margin-right: 10px;
+ }
+}
+
+footer {
+ margin-top: 20px;
+ > .boldFont {
+ margin-top: 10px;
+ }
+} | Unknown | ๋ฐ์ํ ์์ฃผ ์ข๋ค์!!
๋ธ๋ ์ดํฌ ํฌ์ธํธ๋ ๊ธฐํ๋ง๋ค ๋ฌ๋ผ์ง์ง๋ง ๋ณดํต ํ๋ธ๋ฆฟ๊ณผ ๋ฐ์คํฌํ์ ๊ตฌ๋ถ์ ์ 1078px์ด๋ผ๋ ์ ์์๋์ธ์!
๋ชจ๋ฐ์ผ๊ณผ ํ๋ธ๋ฆฟ์ 768px์
๋๋ค! |
@@ -0,0 +1,285 @@
+@import 'https://fonts.googleapis.com/css2?family=Lobster&display=swap';
+@media screen and (max-width: 1200px) {
+ .mainRight {
+ display: none;
+ }
+
+ .article {
+ width: 100%;
+ }
+}
+
+body {
+ margin: 0;
+ padding: 0;
+ border-collapse: collapse;
+}
+
+article {
+ width: 800px;
+ background-color: white;
+}
+
+nav {
+ display: flex;
+ justify-content: space-around;
+ align-items: center;
+ margin: 0px 170px;
+ height: 60px;
+}
+
+.logo {
+ width: 30px;
+ height: 30px;
+ padding-right: 15px;
+ border-right: 1px solid black;
+}
+
+.rightIcon {
+ width: 30px;
+ height: 30px;
+ margin-right: 30px;
+}
+
+.instagram {
+ margin-left: 15px;
+ font-family: 'Lobster', cursive;
+ font-size: 33px;
+ font-weight: 1;
+}
+
+.search {
+ outline: none;
+}
+
+.writeComment {
+ width: 100%;
+ height: 40px;
+ padding-left: 10px;
+ border: 1px solid #efefef;
+ outline: none;
+}
+
+.search-box {
+ > input {
+ width: 200px;
+ height: 20px;
+ border: 1px solid #dbdbdb;
+ text-align: center;
+ }
+
+ position: relative;
+ > img {
+ position: absolute;
+ width: 11px;
+ height: 11px;
+ left: 75px;
+ top: 7px;
+ }
+}
+
+main {
+ padding: 60px 0px;
+ background-color: #fafafa;
+}
+
+.content {
+ display: flex;
+ justify-content: space-around;
+ flex-direction: row;
+ margin: 0px 350px;
+}
+
+.mainRight {
+ width: 330px;
+ margin-left: 10px;
+}
+
+.feedTop {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ width: 780px;
+ padding: 10px 10px;
+ border: 1px solid #e6e6e6;
+}
+
+.feedUser {
+ display: flex;
+ align-items: center;
+}
+
+.feedPicture {
+ height: 800px;
+ border: 1px solid #e6e6e6;
+}
+
+.feedId {
+ margin-left: 10px;
+}
+
+.feedMore {
+ width: 15px;
+ height: 15px;
+}
+
+.smallUserPicture {
+ width: 40px;
+ height: 40px;
+ border: 1px solid #e6e6e6;
+ border-radius: 50px;
+}
+
+.feedIcons {
+ > img {
+ width: 27px;
+ height: 27px;
+ }
+
+ > div {
+ > img {
+ width: 27px;
+ height: 27px;
+ }
+ }
+ display: flex;
+ justify-content: space-between;
+ flex-direction: row;
+ margin: 0px;
+}
+
+.feedBottom {
+ padding: 10px 10px;
+ border-left: 1px solid #efefef;
+ border-right: 1px solid #efefef;
+ border-bottom: 1px solid #efefef;
+}
+
+.FeedBottomLeftIcon {
+ > img {
+ padding-right: 10px;
+ }
+}
+
+.like {
+ > img {
+ width: 15px;
+ height: 15px;
+ margin-right: 5px;
+ border: 1px solid #e6e6e6;
+ border-radius: 7px;
+ }
+ display: flex;
+ align-items: center;
+}
+
+.comment {
+ > div {
+ > div {
+ color: #a4a4a4;
+ }
+ }
+}
+
+.commentIcons {
+ float: right;
+ display: inline;
+ width: 15px;
+ height: 15px;
+ margin-left: 5px;
+}
+
+.boldFont {
+ font-weight: bolder;
+}
+
+.addCommentFrom {
+ position: relative;
+ width: 786px;
+}
+
+.postingButton {
+ position: absolute;
+ color: #cde6fc;
+ background-color: white;
+ top: 14px;
+ right: 10px;
+ border: 0;
+ outline: 0;
+}
+
+.rightTop {
+ display: flex;
+ align-items: center;
+ width: 300px;
+}
+
+.wecodeLogo {
+ width: 60px;
+ height: 60px;
+ margin-right: 20px;
+ border-radius: 50px;
+}
+
+.lightFont {
+ color: #9e9e9e;
+}
+
+.followFont {
+ color: #3797f0;
+}
+
+.rightMiddle {
+ height: 200px;
+ margin: 20px 0px;
+ padding: 12px;
+ background: white;
+ border: 3px solid #e6e6e6;
+ border-radius: 7px;
+ overflow: scroll;
+}
+
+.seeAllStory {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+}
+
+.friendsRecommendContainer {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+}
+
+.story {
+ display: flex;
+ align-items: center;
+ margin: 10px;
+
+ > img {
+ width: 40px;
+ height: 40px;
+ margin-right: 10px;
+ border-radius: 50px;
+ border: 2px solid #d93081;
+ }
+}
+
+.friendsRecommend {
+ display: flex;
+ align-items: center;
+ margin: 10px;
+ > img {
+ width: 40px;
+ height: 40px;
+ border-radius: 50px;
+ margin-right: 10px;
+ }
+}
+
+footer {
+ margin-top: 20px;
+ > .boldFont {
+ margin-top: 10px;
+ }
+} | Unknown | ๊ฐ์ ์คํ์ผ์ ๊ฒฝ์ฐ์๋ ์ค๋ณตํ์ฌ ์ฃผ์์ง ๋ง๊ณ ๊ฐ์ ํด๋์ค๋ช
์ ์ฌ์ฉํ์
๋ ๋ฉ๋๋ค! |
@@ -0,0 +1,125 @@
+import React from 'react';
+import Comment from '../Comment/Comment';
+import './Feed.scss';
+
+class Feed extends React.Component {
+ constructor(props) {
+ super(props);
+ const { comment } = this.props.data;
+ this.state = {
+ comment: comment,
+ commentInputValue: '',
+ };
+ }
+
+ addComment = () => {
+ const { comment, commentInputValue } = this.state;
+ if (commentInputValue.length >= 1) {
+ const newComment = {
+ id: comment.length + 1,
+ content: commentInputValue,
+ isLiked: false,
+ };
+ this.setState({
+ comment: [...comment, newComment],
+ commentInputValue: '',
+ });
+ }
+ };
+
+ deleteComment = e => {
+ const { comment } = this.state;
+ const deleteCommentId = Number(e.target.id);
+ const result = comment.filter(comment => comment.id !== deleteCommentId);
+ this.setState({
+ comment: result,
+ });
+ };
+
+ inputEnterPress = e => {
+ if (e.key === 'Enter') {
+ e.preventDefault();
+ this.addComment();
+ }
+ };
+
+ onChange = e => {
+ const { value } = e.target;
+ this.setState({
+ commentInputValue: value,
+ });
+ };
+
+ render() {
+ const { inputEnterPress, onChange, addComment, deleteComment } = this;
+ const { commentInputValue, comment } = this.state;
+ const { alt, img, userName } = this.props.data;
+
+ return (
+ <div className="feed">
+ <article>
+ <div className="feedTop">
+ <div className="feedUser">
+ <img className="smallUserPicture" alt={alt} src={img} />
+ <div className="feedId boldFont">{userName}</div>
+ </div>
+ <img
+ className="feedMore"
+ alt="๋๋ณด๊ธฐ"
+ src="/images/youngho/more.png"
+ />
+ </div>
+ <img className="feedPicture" alt="ํผ๋์ฌ์ง" src={img} />
+ <div className="feedBottom">
+ <div className="feedIcons">
+ <div className="FeedBottomLeftIcon">
+ <img alt="๋นจ๊ฐ์ํํธ" src="/images/youngho/redHeart.png" />
+ <img alt="๋ฉ์ธ์ง" src="/images/youngho/speech-bubble.png" />
+ <img alt="์
๋ก๋" src="/images/youngho/upload.png" />
+ </div>
+ <img alt="์ ์ฅ" src="/images/youngho/ribbon.png" />
+ </div>
+ <div className="like">
+ <img alt="์ข์์๋ฅผ ๋๋ฅธ ์ฌ๋ ์ฌ์ง" src={img} />
+ <span className="boldFont">manja</span>๋
+ <span className="boldFont">์ธ 7๋ช
</span>์ด ์ข์ํฉ๋๋ค
+ </div>
+ {comment.map(comment => {
+ return (
+ <Comment
+ key={comment.id}
+ id={comment.id}
+ userName={comment.userName}
+ comment={comment.content}
+ isLiked={comment.isLiked}
+ deleteComment={deleteComment}
+ />
+ );
+ })}
+ </div>
+ <form className="addCommentFrom">
+ <input
+ className="writeComment"
+ type="text"
+ placeholder="๋๊ธ ๋ฌ๊ธฐ..."
+ onKeyPress={inputEnterPress}
+ onChange={onChange}
+ value={commentInputValue}
+ />
+ <input
+ className={`postingButton ${
+ commentInputValue.length ? 'activeButton' : ''
+ }`}
+ type="button"
+ defaultValue="๊ฒ์"
+ onClick={addComment}
+ disabled={commentInputValue.length ? false : true}
+ />
+ </form>
+ </article>
+ </div>
+ );
+ }
+}
+
+export default Feed; | JavaScript | import ๊ตฌ๋ถ์ ๋๋ฌด ์ข์ง๋ง ์ค๋ฐ๊ฟ์ ์ํ์
๋ ๋ฉ๋๋ค!!! |
@@ -0,0 +1,125 @@
+import React from 'react';
+import Comment from '../Comment/Comment';
+import './Feed.scss';
+
+class Feed extends React.Component {
+ constructor(props) {
+ super(props);
+ const { comment } = this.props.data;
+ this.state = {
+ comment: comment,
+ commentInputValue: '',
+ };
+ }
+
+ addComment = () => {
+ const { comment, commentInputValue } = this.state;
+ if (commentInputValue.length >= 1) {
+ const newComment = {
+ id: comment.length + 1,
+ content: commentInputValue,
+ isLiked: false,
+ };
+ this.setState({
+ comment: [...comment, newComment],
+ commentInputValue: '',
+ });
+ }
+ };
+
+ deleteComment = e => {
+ const { comment } = this.state;
+ const deleteCommentId = Number(e.target.id);
+ const result = comment.filter(comment => comment.id !== deleteCommentId);
+ this.setState({
+ comment: result,
+ });
+ };
+
+ inputEnterPress = e => {
+ if (e.key === 'Enter') {
+ e.preventDefault();
+ this.addComment();
+ }
+ };
+
+ onChange = e => {
+ const { value } = e.target;
+ this.setState({
+ commentInputValue: value,
+ });
+ };
+
+ render() {
+ const { inputEnterPress, onChange, addComment, deleteComment } = this;
+ const { commentInputValue, comment } = this.state;
+ const { alt, img, userName } = this.props.data;
+
+ return (
+ <div className="feed">
+ <article>
+ <div className="feedTop">
+ <div className="feedUser">
+ <img className="smallUserPicture" alt={alt} src={img} />
+ <div className="feedId boldFont">{userName}</div>
+ </div>
+ <img
+ className="feedMore"
+ alt="๋๋ณด๊ธฐ"
+ src="/images/youngho/more.png"
+ />
+ </div>
+ <img className="feedPicture" alt="ํผ๋์ฌ์ง" src={img} />
+ <div className="feedBottom">
+ <div className="feedIcons">
+ <div className="FeedBottomLeftIcon">
+ <img alt="๋นจ๊ฐ์ํํธ" src="/images/youngho/redHeart.png" />
+ <img alt="๋ฉ์ธ์ง" src="/images/youngho/speech-bubble.png" />
+ <img alt="์
๋ก๋" src="/images/youngho/upload.png" />
+ </div>
+ <img alt="์ ์ฅ" src="/images/youngho/ribbon.png" />
+ </div>
+ <div className="like">
+ <img alt="์ข์์๋ฅผ ๋๋ฅธ ์ฌ๋ ์ฌ์ง" src={img} />
+ <span className="boldFont">manja</span>๋
+ <span className="boldFont">์ธ 7๋ช
</span>์ด ์ข์ํฉ๋๋ค
+ </div>
+ {comment.map(comment => {
+ return (
+ <Comment
+ key={comment.id}
+ id={comment.id}
+ userName={comment.userName}
+ comment={comment.content}
+ isLiked={comment.isLiked}
+ deleteComment={deleteComment}
+ />
+ );
+ })}
+ </div>
+ <form className="addCommentFrom">
+ <input
+ className="writeComment"
+ type="text"
+ placeholder="๋๊ธ ๋ฌ๊ธฐ..."
+ onKeyPress={inputEnterPress}
+ onChange={onChange}
+ value={commentInputValue}
+ />
+ <input
+ className={`postingButton ${
+ commentInputValue.length ? 'activeButton' : ''
+ }`}
+ type="button"
+ defaultValue="๊ฒ์"
+ onClick={addComment}
+ disabled={commentInputValue.length ? false : true}
+ />
+ </form>
+ </article>
+ </div>
+ );
+ }
+}
+
+export default Feed; | JavaScript | ์ด๋ ๊ฒ ๊ตฌ์กฐ๋ถํดํ ๋น ๋๋ฌด ์ข๋ค์!! |
@@ -0,0 +1,74 @@
+[
+ {
+ "id": 1,
+ "userName": "bbangho",
+ "alt": "wecode",
+ "img": "/images/youngho/hanRiver.jpeg",
+ "comment": [
+ {
+ "id": 1,
+ "userName": "bbangho",
+ "content": "ํ๊ฐ ๋ค๋
๊ฐ~ โ๏ธ",
+ "isLiked": true
+ },
+ {
+ "id": 2,
+ "userName": "manja",
+ "content": "ํ๊ฐ ๊ฐฑ~ ๐ซ ๐ซ",
+ "isLiked": true
+ }
+ ]
+ },
+ {
+ "id": 2,
+ "userName": "joonsikyang",
+ "alt": "wecode",
+ "img": "/images/youngho/we.jpeg",
+ "comment": [
+ {
+ "id": 1,
+ "userName": "joonsikyang",
+ "content": "Work hard ๐คฏ",
+ "isLiked": true
+ },
+ {
+ "id": 2,
+ "userName": "bbangho",
+ "content": "Go for it ๐คฃ",
+ "isLiked": false
+ },
+ {
+ "id": 3,
+ "userName": "manja",
+ "content": "๐ฅ๐ฅ",
+ "isLiked": false
+ }
+ ]
+ },
+ {
+ "id": 3,
+ "userName": "jayPark",
+ "alt": "wecode",
+ "img": "/images/youngho/we.jpeg",
+ "comment": [
+ {
+ "id": 1,
+ "userName": "jayPark",
+ "content": "Let's get it",
+ "isLiked": true
+ },
+ {
+ "id": 2,
+ "userName": "bbanho",
+ "content": "Skrt~ ๐",
+ "isLiked": false
+ },
+ {
+ "id": 3,
+ "userName": "gildong",
+ "content": "Yo~ ๐",
+ "isLiked": true
+ }
+ ]
+ }
+] | Unknown | ๊ฐ์ฌํฉ๋๋ค! |
@@ -1,10 +1,94 @@
import React from 'react';
+import { Link } from 'react-router-dom';
+
+import './Login.scss';
class Login extends React.Component {
+ constructor() {
+ super();
+ this.state = {
+ loginId: '',
+ loginPassword: '',
+ };
+ }
+
+ handleLoginInput = e => {
+ const { value, name } = e.target;
+ this.setState({
+ [name]: value,
+ });
+ };
+
+ handleLogin = () => {
+ fetch('http://10.58.0.84:8000/users/login', {
+ method: 'POST',
+ body: JSON.stringify({
+ email: this.state.loginId,
+ password: this.state.loginPassword,
+ }),
+ })
+ .then(response => response.json())
+ .then(result => console.log('๊ฒฐ๊ณผ: ', result));
+ };
+
+ // handleLogin = () => {
+ // fetch('http://10.58.0.84:8000/users/signup', {
+ // method: 'POST',
+ // body: JSON.stringify({
+ // name: '๊น์ํธ',
+ // email: this.state.loginId,
+ // password: this.state.loginPassword,
+ // phone_number: '01012345678',
+ // date_of_birth: '1995-07-07',
+ // gender: 'M',
+ // address: 'Seoul',
+ // }),
+ // })
+ // .then(response => response.json())
+ // .then(result => console.log('๊ฒฐ๊ณผ: ', result));
+ // };
+
render() {
+ const { checkIdPassword, handleLoginInput } = this;
+ const { loginId, loginPassword } = this.state;
+
+ const condition =
+ loginId.length >= 5 && loginPassword.length >= 5 && loginId.includes('@');
+
return (
<div>
- <h3>๋ก๊ทธ์ธ</h3>
+ <div className="container">
+ <header className="header">Westagram</header>
+ <form className="loginForm" onKeyUp={checkIdPassword}>
+ <input
+ id="id"
+ name="loginId"
+ type="text"
+ placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ"
+ onChange={handleLoginInput}
+ />
+ <input
+ id="password"
+ name="loginPassword"
+ type="password"
+ placeholder="๋น๋ฐ๋ฒํธ"
+ onChange={handleLoginInput}
+ />
+ <Link to="/main">
+ <button
+ onClick={this.handleLogin}
+ className={condition ? 'buttonActivate' : 'buttonDisabled'}
+ id="loginButton"
+ disabled={condition ? false : true}
+ >
+ ๋ก๊ทธ์ธ
+ </button>
+ </Link>
+ </form>
+ <a href="#!" className="findPassword">
+ ๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?
+ </a>
+ </div>
</div>
);
} | JavaScript | ๋ฐ์ ์๋ฃํ์ต๋๋ค! |
@@ -0,0 +1,78 @@
+@import 'https://fonts.googleapis.com/css2?family=Lobster&display=swap';
+body {
+ background-color: #fafafa;
+}
+
+.container {
+ text-align: center;
+ width: 600px;
+ height: 600px;
+ margin: 50px auto 0 auto;
+ border: 1px solid #e6e6e6;
+ background-color: white;
+}
+
+.header {
+ padding: 30px;
+ font-family: 'Lobster', cursive;
+ font-size: 70px;
+ font-weight: 1px;
+}
+
+.loginForm {
+ width: 425px;
+ margin: 0 auto;
+}
+
+#id {
+ display: block;
+ width: 100%;
+ margin: 20px 0px auto;
+ padding: 15px;
+ border: 1px solid #efefef;
+ background-color: #fafafa;
+ border-radius: 5px;
+ font-size: 20px;
+}
+
+#password {
+ display: block;
+ width: 100%;
+ margin: 20px 0px auto;
+ padding: 15px;
+ border: 1px solid #efefef;
+ background-color: #fafafa;
+ border-radius: 5px;
+ font-size: 20px;
+}
+
+#loginButton {
+ display: block;
+ width: 459px;
+ margin: 20px 0px auto;
+ padding: 15px;
+ border: 0px;
+ border-radius: 5px;
+ color: white;
+ font-size: 20px;
+}
+
+.findPassword {
+ display: block;
+ height: 50px;
+ margin-top: 180px;
+ font-size: 18px;
+ text-decoration: none;
+}
+
+.buttonDisabled {
+ background-color: #c5e1fc;
+}
+
+.buttonActivate {
+ background-color: #0095f6;
+}
+
+a {
+ text-decoration: none;
+} | Unknown | ๋ฐ์ ์๋ฃํ์ต๋๋ค! |
@@ -0,0 +1,78 @@
+@import 'https://fonts.googleapis.com/css2?family=Lobster&display=swap';
+body {
+ background-color: #fafafa;
+}
+
+.container {
+ text-align: center;
+ width: 600px;
+ height: 600px;
+ margin: 50px auto 0 auto;
+ border: 1px solid #e6e6e6;
+ background-color: white;
+}
+
+.header {
+ padding: 30px;
+ font-family: 'Lobster', cursive;
+ font-size: 70px;
+ font-weight: 1px;
+}
+
+.loginForm {
+ width: 425px;
+ margin: 0 auto;
+}
+
+#id {
+ display: block;
+ width: 100%;
+ margin: 20px 0px auto;
+ padding: 15px;
+ border: 1px solid #efefef;
+ background-color: #fafafa;
+ border-radius: 5px;
+ font-size: 20px;
+}
+
+#password {
+ display: block;
+ width: 100%;
+ margin: 20px 0px auto;
+ padding: 15px;
+ border: 1px solid #efefef;
+ background-color: #fafafa;
+ border-radius: 5px;
+ font-size: 20px;
+}
+
+#loginButton {
+ display: block;
+ width: 459px;
+ margin: 20px 0px auto;
+ padding: 15px;
+ border: 0px;
+ border-radius: 5px;
+ color: white;
+ font-size: 20px;
+}
+
+.findPassword {
+ display: block;
+ height: 50px;
+ margin-top: 180px;
+ font-size: 18px;
+ text-decoration: none;
+}
+
+.buttonDisabled {
+ background-color: #c5e1fc;
+}
+
+.buttonActivate {
+ background-color: #0095f6;
+}
+
+a {
+ text-decoration: none;
+} | Unknown | ๋ฐ์ ์๋ฃํ์ต๋๋ค! |
@@ -1,10 +1,178 @@
import React from 'react';
+import Nav from '../../../components/Nav/Nav';
+import Feed from '../../../components/Feed/Feed';
+import './Main.scss';
+
class Main extends React.Component {
+ constructor() {
+ super();
+ this.state = {
+ feeds: [],
+ };
+ }
+
+ componentDidMount() {
+ fetch('/data/feedData.json', {
+ method: 'GET',
+ })
+ .then(res => res.json())
+ .then(data => {
+ this.setState({
+ feeds: data,
+ });
+ });
+ }
+
render() {
+ const { feeds } = this.state;
+
+ const STORIES = [
+ {
+ alt: '์คํ ๋ฆฌ ํ๋กํ ์ฌ์ง',
+ img: '/images/youngho/wecode.png',
+ name: 'wecorder1',
+ time: 43,
+ },
+ {
+ alt: '์คํ ๋ฆฌ ํ๋กํ ์ฌ์ง',
+ img: '/images/youngho/wecode.png',
+ name: 'wecorder2',
+ time: 3,
+ },
+ {
+ alt: '์คํ ๋ฆฌ ํ๋กํ ์ฌ์ง',
+ img: '/images/youngho/wecode.png',
+ name: 'wecorder3',
+ time: 23,
+ },
+ {
+ alt: '์คํ ๋ฆฌ ํ๋กํ ์ฌ์ง',
+ img: '/images/youngho/wecode.png',
+ name: 'wecorder4',
+ time: 27,
+ },
+ {
+ alt: '์คํ ๋ฆฌ ํ๋กํ ์ฌ์ง',
+ img: '/images/youngho/wecode.png',
+ name: 'wecorder5',
+ time: 13,
+ },
+ ];
+
+ const Stories = STORIES.map(store => {
+ return (
+ <div className="story">
+ <img alt={store.alt} src={store.img} />
+ <div>
+ <div className="boldFont">{store.name}</div>
+ <div className="lightFont">{store.time}๋ถ ์ </div>
+ </div>
+ </div>
+ );
+ });
return (
<div>
- <h3>๋ฉ์ธ</h3>
+ <Nav />
+ <main>
+ <div className="content">
+ <div>
+ {feeds.map(feed => {
+ return <Feed key={`feed${feed.id}`} data={feed} />;
+ })}
+ </div>
+ <div className="mainRight">
+ <div className="rightTop">
+ <img
+ className="wecodeLogo"
+ alt="์์ฝ๋ ์ฌ์ง"
+ src="/images/youngho/wecode.png"
+ />
+ <div>
+ <div className="boldFont">wecode_bootcamp</div>
+ <div className="lightFont">WeCode | ์์ฝ๋</div>
+ </div>
+ </div>
+ <div className="rightMiddle">
+ <div className="seeAllStory">
+ <div className="lightFont">์คํ ๋ฆฌ</div>
+ <div className="boldFont">๋ชจ๋ ๋ณด๊ธฐ</div>
+ </div>
+ <div className="seeStory">{Stories}</div>
+ </div>
+ <div className="rightMiddle">
+ <div className="friendsRecommendContainer">
+ <div className="lightFont">ํ์๋์ ์ํ ์ถ์ฒ</div>
+ <div className="boldFont">๋ชจ๋ ๋ณด๊ธฐ</div>
+ </div>
+ <div className="friendsRecommendList">
+ <div className="friendsRecommend">
+ <img
+ alt="์น๊ตฌ์ถ์ฒ ํ๋กํ ์ฌ์ง"
+ src="/images/youngho/wecode.png"
+ />
+ <div>
+ <div className="boldFont">ํ๊ธธ๋</div>
+ <div className="lightFont">๋ธ๋ผ๋ธ๋ผ๋ ์ธ 2๋ช
์ด ...</div>
+ </div>
+ <div className="followFont boldFont">ํ๋ก์ฐ</div>
+ </div>
+ <div className="friendsRecommend">
+ <img
+ alt="์น๊ตฌ์ถ์ฒ ํ๋กํ ์ฌ์ง"
+ src="/images/youngho/wecode.png"
+ />
+ <div>
+ <div className="boldFont">์๋ฌด๊ฐ</div>
+ <div className="lightFont">์๋์๋๋ ์ธ 2๋ช
์ด ...</div>
+ </div>
+ <div className="followFont boldFont">ํ๋ก์ฐ</div>
+ </div>
+ <div className="friendsRecommend">
+ <img
+ alt="์น๊ตฌ์ถ์ฒ ํ๋กํ ์ฌ์ง"
+ src="/images/youngho/wecode.png"
+ />
+ <div>
+ <div className="boldFont">์ด์ฉ๊ตฌ</div>
+ <div className="lightFont">์๋ผ์๋ผ๋ ์ธ 2๋ช
์ด ...</div>
+ </div>
+ <div className="followFont boldFont">ํ๋ก์ฐ</div>
+ </div>
+ <div className="friendsRecommend">
+ <img
+ alt="์น๊ตฌ์ถ์ฒ ํ๋กํ ์ฌ์ง"
+ src="/images/youngho/wecode.png"
+ />
+ <div>
+ <div className="boldFont">์ ์ฉ๊ตฌ</div>
+ <div className="lightFont">์๋ก์๋ก๋ ์ธ 2๋ช
์ด ...</div>
+ </div>
+ <div className="followFont boldFont">ํ๋ก์ฐ</div>
+ </div>
+ <div className="friendsRecommend">
+ <img
+ alt="์น๊ตฌ์ถ์ฒ ํ๋กํ ์ฌ์ง"
+ src="/images/youngho/wecode.png"
+ />
+ <div>
+ <div className="boldFont">์ผ๋ผ์ผ๋ผ</div>
+ <div className="lightFont">๋ธ๋ผ๋ธ๋ผ๋ ์ธ 2๋ช
์ด ...</div>
+ </div>
+ <div className="followFont boldFont">ํ๋ก์ฐ</div>
+ </div>
+ </div>
+ </div>
+ <footer>
+ <div className="lightFont">
+ Westagram ์ ๋ณด . ์ง์ . ํ๋ณด ์ผํฐ . API . ์ฑ์ฉ์ ๋ณด .
+ ๊ฐ์ธ์ ๋ณด์ฒ๋ฆฌ๋ฐฉ์นจ . ์ฝ๊ด . ๋๋ ํฐ๋ฆฌ . ํ๋กํ . ํด์ํ๊ทธ . ์ธ์ด
+ </div>
+ <div className="lightFont boldFont">ยฉ 2021 WESTAGRAM</div>
+ </footer>
+ </div>
+ </div>
+ </main>
</div>
);
} | JavaScript | ๋ฐ์ ์๋ฃํ์ต๋๋ค! |
@@ -1,10 +1,178 @@
import React from 'react';
+import Nav from '../../../components/Nav/Nav';
+import Feed from '../../../components/Feed/Feed';
+import './Main.scss';
+
class Main extends React.Component {
+ constructor() {
+ super();
+ this.state = {
+ feeds: [],
+ };
+ }
+
+ componentDidMount() {
+ fetch('/data/feedData.json', {
+ method: 'GET',
+ })
+ .then(res => res.json())
+ .then(data => {
+ this.setState({
+ feeds: data,
+ });
+ });
+ }
+
render() {
+ const { feeds } = this.state;
+
+ const STORIES = [
+ {
+ alt: '์คํ ๋ฆฌ ํ๋กํ ์ฌ์ง',
+ img: '/images/youngho/wecode.png',
+ name: 'wecorder1',
+ time: 43,
+ },
+ {
+ alt: '์คํ ๋ฆฌ ํ๋กํ ์ฌ์ง',
+ img: '/images/youngho/wecode.png',
+ name: 'wecorder2',
+ time: 3,
+ },
+ {
+ alt: '์คํ ๋ฆฌ ํ๋กํ ์ฌ์ง',
+ img: '/images/youngho/wecode.png',
+ name: 'wecorder3',
+ time: 23,
+ },
+ {
+ alt: '์คํ ๋ฆฌ ํ๋กํ ์ฌ์ง',
+ img: '/images/youngho/wecode.png',
+ name: 'wecorder4',
+ time: 27,
+ },
+ {
+ alt: '์คํ ๋ฆฌ ํ๋กํ ์ฌ์ง',
+ img: '/images/youngho/wecode.png',
+ name: 'wecorder5',
+ time: 13,
+ },
+ ];
+
+ const Stories = STORIES.map(store => {
+ return (
+ <div className="story">
+ <img alt={store.alt} src={store.img} />
+ <div>
+ <div className="boldFont">{store.name}</div>
+ <div className="lightFont">{store.time}๋ถ ์ </div>
+ </div>
+ </div>
+ );
+ });
return (
<div>
- <h3>๋ฉ์ธ</h3>
+ <Nav />
+ <main>
+ <div className="content">
+ <div>
+ {feeds.map(feed => {
+ return <Feed key={`feed${feed.id}`} data={feed} />;
+ })}
+ </div>
+ <div className="mainRight">
+ <div className="rightTop">
+ <img
+ className="wecodeLogo"
+ alt="์์ฝ๋ ์ฌ์ง"
+ src="/images/youngho/wecode.png"
+ />
+ <div>
+ <div className="boldFont">wecode_bootcamp</div>
+ <div className="lightFont">WeCode | ์์ฝ๋</div>
+ </div>
+ </div>
+ <div className="rightMiddle">
+ <div className="seeAllStory">
+ <div className="lightFont">์คํ ๋ฆฌ</div>
+ <div className="boldFont">๋ชจ๋ ๋ณด๊ธฐ</div>
+ </div>
+ <div className="seeStory">{Stories}</div>
+ </div>
+ <div className="rightMiddle">
+ <div className="friendsRecommendContainer">
+ <div className="lightFont">ํ์๋์ ์ํ ์ถ์ฒ</div>
+ <div className="boldFont">๋ชจ๋ ๋ณด๊ธฐ</div>
+ </div>
+ <div className="friendsRecommendList">
+ <div className="friendsRecommend">
+ <img
+ alt="์น๊ตฌ์ถ์ฒ ํ๋กํ ์ฌ์ง"
+ src="/images/youngho/wecode.png"
+ />
+ <div>
+ <div className="boldFont">ํ๊ธธ๋</div>
+ <div className="lightFont">๋ธ๋ผ๋ธ๋ผ๋ ์ธ 2๋ช
์ด ...</div>
+ </div>
+ <div className="followFont boldFont">ํ๋ก์ฐ</div>
+ </div>
+ <div className="friendsRecommend">
+ <img
+ alt="์น๊ตฌ์ถ์ฒ ํ๋กํ ์ฌ์ง"
+ src="/images/youngho/wecode.png"
+ />
+ <div>
+ <div className="boldFont">์๋ฌด๊ฐ</div>
+ <div className="lightFont">์๋์๋๋ ์ธ 2๋ช
์ด ...</div>
+ </div>
+ <div className="followFont boldFont">ํ๋ก์ฐ</div>
+ </div>
+ <div className="friendsRecommend">
+ <img
+ alt="์น๊ตฌ์ถ์ฒ ํ๋กํ ์ฌ์ง"
+ src="/images/youngho/wecode.png"
+ />
+ <div>
+ <div className="boldFont">์ด์ฉ๊ตฌ</div>
+ <div className="lightFont">์๋ผ์๋ผ๋ ์ธ 2๋ช
์ด ...</div>
+ </div>
+ <div className="followFont boldFont">ํ๋ก์ฐ</div>
+ </div>
+ <div className="friendsRecommend">
+ <img
+ alt="์น๊ตฌ์ถ์ฒ ํ๋กํ ์ฌ์ง"
+ src="/images/youngho/wecode.png"
+ />
+ <div>
+ <div className="boldFont">์ ์ฉ๊ตฌ</div>
+ <div className="lightFont">์๋ก์๋ก๋ ์ธ 2๋ช
์ด ...</div>
+ </div>
+ <div className="followFont boldFont">ํ๋ก์ฐ</div>
+ </div>
+ <div className="friendsRecommend">
+ <img
+ alt="์น๊ตฌ์ถ์ฒ ํ๋กํ ์ฌ์ง"
+ src="/images/youngho/wecode.png"
+ />
+ <div>
+ <div className="boldFont">์ผ๋ผ์ผ๋ผ</div>
+ <div className="lightFont">๋ธ๋ผ๋ธ๋ผ๋ ์ธ 2๋ช
์ด ...</div>
+ </div>
+ <div className="followFont boldFont">ํ๋ก์ฐ</div>
+ </div>
+ </div>
+ </div>
+ <footer>
+ <div className="lightFont">
+ Westagram ์ ๋ณด . ์ง์ . ํ๋ณด ์ผํฐ . API . ์ฑ์ฉ์ ๋ณด .
+ ๊ฐ์ธ์ ๋ณด์ฒ๋ฆฌ๋ฐฉ์นจ . ์ฝ๊ด . ๋๋ ํฐ๋ฆฌ . ํ๋กํ . ํด์ํ๊ทธ . ์ธ์ด
+ </div>
+ <div className="lightFont boldFont">ยฉ 2021 WESTAGRAM</div>
+ </footer>
+ </div>
+ </div>
+ </main>
</div>
);
} | JavaScript | ๋ฐ์ ์๋ฃํ์ต๋๋ค! |
@@ -0,0 +1,285 @@
+@import 'https://fonts.googleapis.com/css2?family=Lobster&display=swap';
+@media screen and (max-width: 1200px) {
+ .mainRight {
+ display: none;
+ }
+
+ .article {
+ width: 100%;
+ }
+}
+
+body {
+ margin: 0;
+ padding: 0;
+ border-collapse: collapse;
+}
+
+article {
+ width: 800px;
+ background-color: white;
+}
+
+nav {
+ display: flex;
+ justify-content: space-around;
+ align-items: center;
+ margin: 0px 170px;
+ height: 60px;
+}
+
+.logo {
+ width: 30px;
+ height: 30px;
+ padding-right: 15px;
+ border-right: 1px solid black;
+}
+
+.rightIcon {
+ width: 30px;
+ height: 30px;
+ margin-right: 30px;
+}
+
+.instagram {
+ margin-left: 15px;
+ font-family: 'Lobster', cursive;
+ font-size: 33px;
+ font-weight: 1;
+}
+
+.search {
+ outline: none;
+}
+
+.writeComment {
+ width: 100%;
+ height: 40px;
+ padding-left: 10px;
+ border: 1px solid #efefef;
+ outline: none;
+}
+
+.search-box {
+ > input {
+ width: 200px;
+ height: 20px;
+ border: 1px solid #dbdbdb;
+ text-align: center;
+ }
+
+ position: relative;
+ > img {
+ position: absolute;
+ width: 11px;
+ height: 11px;
+ left: 75px;
+ top: 7px;
+ }
+}
+
+main {
+ padding: 60px 0px;
+ background-color: #fafafa;
+}
+
+.content {
+ display: flex;
+ justify-content: space-around;
+ flex-direction: row;
+ margin: 0px 350px;
+}
+
+.mainRight {
+ width: 330px;
+ margin-left: 10px;
+}
+
+.feedTop {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ width: 780px;
+ padding: 10px 10px;
+ border: 1px solid #e6e6e6;
+}
+
+.feedUser {
+ display: flex;
+ align-items: center;
+}
+
+.feedPicture {
+ height: 800px;
+ border: 1px solid #e6e6e6;
+}
+
+.feedId {
+ margin-left: 10px;
+}
+
+.feedMore {
+ width: 15px;
+ height: 15px;
+}
+
+.smallUserPicture {
+ width: 40px;
+ height: 40px;
+ border: 1px solid #e6e6e6;
+ border-radius: 50px;
+}
+
+.feedIcons {
+ > img {
+ width: 27px;
+ height: 27px;
+ }
+
+ > div {
+ > img {
+ width: 27px;
+ height: 27px;
+ }
+ }
+ display: flex;
+ justify-content: space-between;
+ flex-direction: row;
+ margin: 0px;
+}
+
+.feedBottom {
+ padding: 10px 10px;
+ border-left: 1px solid #efefef;
+ border-right: 1px solid #efefef;
+ border-bottom: 1px solid #efefef;
+}
+
+.FeedBottomLeftIcon {
+ > img {
+ padding-right: 10px;
+ }
+}
+
+.like {
+ > img {
+ width: 15px;
+ height: 15px;
+ margin-right: 5px;
+ border: 1px solid #e6e6e6;
+ border-radius: 7px;
+ }
+ display: flex;
+ align-items: center;
+}
+
+.comment {
+ > div {
+ > div {
+ color: #a4a4a4;
+ }
+ }
+}
+
+.commentIcons {
+ float: right;
+ display: inline;
+ width: 15px;
+ height: 15px;
+ margin-left: 5px;
+}
+
+.boldFont {
+ font-weight: bolder;
+}
+
+.addCommentFrom {
+ position: relative;
+ width: 786px;
+}
+
+.postingButton {
+ position: absolute;
+ color: #cde6fc;
+ background-color: white;
+ top: 14px;
+ right: 10px;
+ border: 0;
+ outline: 0;
+}
+
+.rightTop {
+ display: flex;
+ align-items: center;
+ width: 300px;
+}
+
+.wecodeLogo {
+ width: 60px;
+ height: 60px;
+ margin-right: 20px;
+ border-radius: 50px;
+}
+
+.lightFont {
+ color: #9e9e9e;
+}
+
+.followFont {
+ color: #3797f0;
+}
+
+.rightMiddle {
+ height: 200px;
+ margin: 20px 0px;
+ padding: 12px;
+ background: white;
+ border: 3px solid #e6e6e6;
+ border-radius: 7px;
+ overflow: scroll;
+}
+
+.seeAllStory {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+}
+
+.friendsRecommendContainer {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+}
+
+.story {
+ display: flex;
+ align-items: center;
+ margin: 10px;
+
+ > img {
+ width: 40px;
+ height: 40px;
+ margin-right: 10px;
+ border-radius: 50px;
+ border: 2px solid #d93081;
+ }
+}
+
+.friendsRecommend {
+ display: flex;
+ align-items: center;
+ margin: 10px;
+ > img {
+ width: 40px;
+ height: 40px;
+ border-radius: 50px;
+ margin-right: 10px;
+ }
+}
+
+footer {
+ margin-top: 20px;
+ > .boldFont {
+ margin-top: 10px;
+ }
+} | Unknown | ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,285 @@
+@import 'https://fonts.googleapis.com/css2?family=Lobster&display=swap';
+@media screen and (max-width: 1200px) {
+ .mainRight {
+ display: none;
+ }
+
+ .article {
+ width: 100%;
+ }
+}
+
+body {
+ margin: 0;
+ padding: 0;
+ border-collapse: collapse;
+}
+
+article {
+ width: 800px;
+ background-color: white;
+}
+
+nav {
+ display: flex;
+ justify-content: space-around;
+ align-items: center;
+ margin: 0px 170px;
+ height: 60px;
+}
+
+.logo {
+ width: 30px;
+ height: 30px;
+ padding-right: 15px;
+ border-right: 1px solid black;
+}
+
+.rightIcon {
+ width: 30px;
+ height: 30px;
+ margin-right: 30px;
+}
+
+.instagram {
+ margin-left: 15px;
+ font-family: 'Lobster', cursive;
+ font-size: 33px;
+ font-weight: 1;
+}
+
+.search {
+ outline: none;
+}
+
+.writeComment {
+ width: 100%;
+ height: 40px;
+ padding-left: 10px;
+ border: 1px solid #efefef;
+ outline: none;
+}
+
+.search-box {
+ > input {
+ width: 200px;
+ height: 20px;
+ border: 1px solid #dbdbdb;
+ text-align: center;
+ }
+
+ position: relative;
+ > img {
+ position: absolute;
+ width: 11px;
+ height: 11px;
+ left: 75px;
+ top: 7px;
+ }
+}
+
+main {
+ padding: 60px 0px;
+ background-color: #fafafa;
+}
+
+.content {
+ display: flex;
+ justify-content: space-around;
+ flex-direction: row;
+ margin: 0px 350px;
+}
+
+.mainRight {
+ width: 330px;
+ margin-left: 10px;
+}
+
+.feedTop {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ width: 780px;
+ padding: 10px 10px;
+ border: 1px solid #e6e6e6;
+}
+
+.feedUser {
+ display: flex;
+ align-items: center;
+}
+
+.feedPicture {
+ height: 800px;
+ border: 1px solid #e6e6e6;
+}
+
+.feedId {
+ margin-left: 10px;
+}
+
+.feedMore {
+ width: 15px;
+ height: 15px;
+}
+
+.smallUserPicture {
+ width: 40px;
+ height: 40px;
+ border: 1px solid #e6e6e6;
+ border-radius: 50px;
+}
+
+.feedIcons {
+ > img {
+ width: 27px;
+ height: 27px;
+ }
+
+ > div {
+ > img {
+ width: 27px;
+ height: 27px;
+ }
+ }
+ display: flex;
+ justify-content: space-between;
+ flex-direction: row;
+ margin: 0px;
+}
+
+.feedBottom {
+ padding: 10px 10px;
+ border-left: 1px solid #efefef;
+ border-right: 1px solid #efefef;
+ border-bottom: 1px solid #efefef;
+}
+
+.FeedBottomLeftIcon {
+ > img {
+ padding-right: 10px;
+ }
+}
+
+.like {
+ > img {
+ width: 15px;
+ height: 15px;
+ margin-right: 5px;
+ border: 1px solid #e6e6e6;
+ border-radius: 7px;
+ }
+ display: flex;
+ align-items: center;
+}
+
+.comment {
+ > div {
+ > div {
+ color: #a4a4a4;
+ }
+ }
+}
+
+.commentIcons {
+ float: right;
+ display: inline;
+ width: 15px;
+ height: 15px;
+ margin-left: 5px;
+}
+
+.boldFont {
+ font-weight: bolder;
+}
+
+.addCommentFrom {
+ position: relative;
+ width: 786px;
+}
+
+.postingButton {
+ position: absolute;
+ color: #cde6fc;
+ background-color: white;
+ top: 14px;
+ right: 10px;
+ border: 0;
+ outline: 0;
+}
+
+.rightTop {
+ display: flex;
+ align-items: center;
+ width: 300px;
+}
+
+.wecodeLogo {
+ width: 60px;
+ height: 60px;
+ margin-right: 20px;
+ border-radius: 50px;
+}
+
+.lightFont {
+ color: #9e9e9e;
+}
+
+.followFont {
+ color: #3797f0;
+}
+
+.rightMiddle {
+ height: 200px;
+ margin: 20px 0px;
+ padding: 12px;
+ background: white;
+ border: 3px solid #e6e6e6;
+ border-radius: 7px;
+ overflow: scroll;
+}
+
+.seeAllStory {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+}
+
+.friendsRecommendContainer {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+}
+
+.story {
+ display: flex;
+ align-items: center;
+ margin: 10px;
+
+ > img {
+ width: 40px;
+ height: 40px;
+ margin-right: 10px;
+ border-radius: 50px;
+ border: 2px solid #d93081;
+ }
+}
+
+.friendsRecommend {
+ display: flex;
+ align-items: center;
+ margin: 10px;
+ > img {
+ width: 40px;
+ height: 40px;
+ border-radius: 50px;
+ margin-right: 10px;
+ }
+}
+
+footer {
+ margin-top: 20px;
+ > .boldFont {
+ margin-top: 10px;
+ }
+} | Unknown | ๋ฐ์ ์๋ฃํ์ต๋๋ค! |
@@ -0,0 +1,125 @@
+import React from 'react';
+import Comment from '../Comment/Comment';
+import './Feed.scss';
+
+class Feed extends React.Component {
+ constructor(props) {
+ super(props);
+ const { comment } = this.props.data;
+ this.state = {
+ comment: comment,
+ commentInputValue: '',
+ };
+ }
+
+ addComment = () => {
+ const { comment, commentInputValue } = this.state;
+ if (commentInputValue.length >= 1) {
+ const newComment = {
+ id: comment.length + 1,
+ content: commentInputValue,
+ isLiked: false,
+ };
+ this.setState({
+ comment: [...comment, newComment],
+ commentInputValue: '',
+ });
+ }
+ };
+
+ deleteComment = e => {
+ const { comment } = this.state;
+ const deleteCommentId = Number(e.target.id);
+ const result = comment.filter(comment => comment.id !== deleteCommentId);
+ this.setState({
+ comment: result,
+ });
+ };
+
+ inputEnterPress = e => {
+ if (e.key === 'Enter') {
+ e.preventDefault();
+ this.addComment();
+ }
+ };
+
+ onChange = e => {
+ const { value } = e.target;
+ this.setState({
+ commentInputValue: value,
+ });
+ };
+
+ render() {
+ const { inputEnterPress, onChange, addComment, deleteComment } = this;
+ const { commentInputValue, comment } = this.state;
+ const { alt, img, userName } = this.props.data;
+
+ return (
+ <div className="feed">
+ <article>
+ <div className="feedTop">
+ <div className="feedUser">
+ <img className="smallUserPicture" alt={alt} src={img} />
+ <div className="feedId boldFont">{userName}</div>
+ </div>
+ <img
+ className="feedMore"
+ alt="๋๋ณด๊ธฐ"
+ src="/images/youngho/more.png"
+ />
+ </div>
+ <img className="feedPicture" alt="ํผ๋์ฌ์ง" src={img} />
+ <div className="feedBottom">
+ <div className="feedIcons">
+ <div className="FeedBottomLeftIcon">
+ <img alt="๋นจ๊ฐ์ํํธ" src="/images/youngho/redHeart.png" />
+ <img alt="๋ฉ์ธ์ง" src="/images/youngho/speech-bubble.png" />
+ <img alt="์
๋ก๋" src="/images/youngho/upload.png" />
+ </div>
+ <img alt="์ ์ฅ" src="/images/youngho/ribbon.png" />
+ </div>
+ <div className="like">
+ <img alt="์ข์์๋ฅผ ๋๋ฅธ ์ฌ๋ ์ฌ์ง" src={img} />
+ <span className="boldFont">manja</span>๋
+ <span className="boldFont">์ธ 7๋ช
</span>์ด ์ข์ํฉ๋๋ค
+ </div>
+ {comment.map(comment => {
+ return (
+ <Comment
+ key={comment.id}
+ id={comment.id}
+ userName={comment.userName}
+ comment={comment.content}
+ isLiked={comment.isLiked}
+ deleteComment={deleteComment}
+ />
+ );
+ })}
+ </div>
+ <form className="addCommentFrom">
+ <input
+ className="writeComment"
+ type="text"
+ placeholder="๋๊ธ ๋ฌ๊ธฐ..."
+ onKeyPress={inputEnterPress}
+ onChange={onChange}
+ value={commentInputValue}
+ />
+ <input
+ className={`postingButton ${
+ commentInputValue.length ? 'activeButton' : ''
+ }`}
+ type="button"
+ defaultValue="๊ฒ์"
+ onClick={addComment}
+ disabled={commentInputValue.length ? false : true}
+ />
+ </form>
+ </article>
+ </div>
+ );
+ }
+}
+
+export default Feed; | JavaScript | ๋ฐ์ ์๋ฃํ์ต๋๋ค! |
@@ -0,0 +1,125 @@
+import React from 'react';
+import Comment from '../Comment/Comment';
+import './Feed.scss';
+
+class Feed extends React.Component {
+ constructor(props) {
+ super(props);
+ const { comment } = this.props.data;
+ this.state = {
+ comment: comment,
+ commentInputValue: '',
+ };
+ }
+
+ addComment = () => {
+ const { comment, commentInputValue } = this.state;
+ if (commentInputValue.length >= 1) {
+ const newComment = {
+ id: comment.length + 1,
+ content: commentInputValue,
+ isLiked: false,
+ };
+ this.setState({
+ comment: [...comment, newComment],
+ commentInputValue: '',
+ });
+ }
+ };
+
+ deleteComment = e => {
+ const { comment } = this.state;
+ const deleteCommentId = Number(e.target.id);
+ const result = comment.filter(comment => comment.id !== deleteCommentId);
+ this.setState({
+ comment: result,
+ });
+ };
+
+ inputEnterPress = e => {
+ if (e.key === 'Enter') {
+ e.preventDefault();
+ this.addComment();
+ }
+ };
+
+ onChange = e => {
+ const { value } = e.target;
+ this.setState({
+ commentInputValue: value,
+ });
+ };
+
+ render() {
+ const { inputEnterPress, onChange, addComment, deleteComment } = this;
+ const { commentInputValue, comment } = this.state;
+ const { alt, img, userName } = this.props.data;
+
+ return (
+ <div className="feed">
+ <article>
+ <div className="feedTop">
+ <div className="feedUser">
+ <img className="smallUserPicture" alt={alt} src={img} />
+ <div className="feedId boldFont">{userName}</div>
+ </div>
+ <img
+ className="feedMore"
+ alt="๋๋ณด๊ธฐ"
+ src="/images/youngho/more.png"
+ />
+ </div>
+ <img className="feedPicture" alt="ํผ๋์ฌ์ง" src={img} />
+ <div className="feedBottom">
+ <div className="feedIcons">
+ <div className="FeedBottomLeftIcon">
+ <img alt="๋นจ๊ฐ์ํํธ" src="/images/youngho/redHeart.png" />
+ <img alt="๋ฉ์ธ์ง" src="/images/youngho/speech-bubble.png" />
+ <img alt="์
๋ก๋" src="/images/youngho/upload.png" />
+ </div>
+ <img alt="์ ์ฅ" src="/images/youngho/ribbon.png" />
+ </div>
+ <div className="like">
+ <img alt="์ข์์๋ฅผ ๋๋ฅธ ์ฌ๋ ์ฌ์ง" src={img} />
+ <span className="boldFont">manja</span>๋
+ <span className="boldFont">์ธ 7๋ช
</span>์ด ์ข์ํฉ๋๋ค
+ </div>
+ {comment.map(comment => {
+ return (
+ <Comment
+ key={comment.id}
+ id={comment.id}
+ userName={comment.userName}
+ comment={comment.content}
+ isLiked={comment.isLiked}
+ deleteComment={deleteComment}
+ />
+ );
+ })}
+ </div>
+ <form className="addCommentFrom">
+ <input
+ className="writeComment"
+ type="text"
+ placeholder="๋๊ธ ๋ฌ๊ธฐ..."
+ onKeyPress={inputEnterPress}
+ onChange={onChange}
+ value={commentInputValue}
+ />
+ <input
+ className={`postingButton ${
+ commentInputValue.length ? 'activeButton' : ''
+ }`}
+ type="button"
+ defaultValue="๊ฒ์"
+ onClick={addComment}
+ disabled={commentInputValue.length ? false : true}
+ />
+ </form>
+ </article>
+ </div>
+ );
+ }
+}
+
+export default Feed; | JavaScript | ๊ฐ์ฌํฉ๋๋ค ๐ |
@@ -0,0 +1,17 @@
+from django.db import models
+
+class User(models.Model):
+ email = models.EmailField(max_length=50, unique=True)
+ password = models.CharField(max_length=100)
+ relation = models.ManyToManyField('self', through='Follow', symmetrical=False)
+
+ class Meta:
+ db_table = "users"
+
+
+class Follow(models.Model):
+ following = models.ForeignKey(User, on_delete = models.SET_NULL, null=True, related_name = "following")
+ follower = models.ForeignKey(User, on_delete = models.SET_NULL, null=True, related_name = "follower")
+
+ class Meta:
+ db_table = "follows"
\ No newline at end of file | Python | ๋ค๋ฏผ๋! ์ ์์ฑํด์ฃผ์
จ๋๋ฐ `email` ์ ๊ฒน์น ์ ์๋ ์ ๋ณด์ด๊ธฐ ๋๋ฌธ์ ํด๋นํ๋ ์ต์
์ ์ถ๊ฐํด์ฃผ์๋๊ฒ ์ข์ต๋๋ค! ์์๋ณด์๊ณ ์๋ง์ ์ต์
์ ์ถ๊ฐํด์ฃผ์ธ์~ |
@@ -0,0 +1,10 @@
+from django.urls import path
+from .views import SignupView, LoginView, FollowView
+
+urlpatterns = [
+ path('/user', SignupView.as_view()),
+ path('/login', LoginView.as_view()),
+ path('/follow', FollowView.as_view()),
+
+]
+'''Error๊ฐ ์๋๋ผ django์ ๊ถ์ฅ์ฌํญ. ํ์ง๋ง ํจํด ์ปจ๋ฒค์
์๋ ์ ์ฌํญ์ด ๋ง๋ค.''' | Python | import ํ์ค ๋ `*` ์ฌ์ฉํ์ง ๋ง์๊ณ ๋ช
ํํ๊ฒ ๊ฐ์ ธ์ค๊ณ ์ถ์ class ๋ฅผ ์ ์ด์ฃผ์ธ์! |
@@ -0,0 +1,10 @@
+from django.urls import path
+from .views import SignupView, LoginView, FollowView
+
+urlpatterns = [
+ path('/user', SignupView.as_view()),
+ path('/login', LoginView.as_view()),
+ path('/follow', FollowView.as_view()),
+
+]
+'''Error๊ฐ ์๋๋ผ django์ ๊ถ์ฅ์ฌํญ. ํ์ง๋ง ํจํด ์ปจ๋ฒค์
์๋ ์ ์ฌํญ์ด ๋ง๋ค.''' | Python | ์ด ๋ถ๋ถ ์ธ์
์ค ํ๋ฒ ์ค๋ช
๋๋ ธ๋๋ฐ, ์ `/` ๊ด๋ จ warning ์ด ๋ฌ๋ค๊ณ ์๊ฐํ์๋์!? |
@@ -0,0 +1,21 @@
+"""westagram URL Configuration
+
+The `urlpatterns` list routes URLs to views. For more information please see:
+ https://docs.djangoproject.com/en/3.1/topics/http/urls/
+Examples:
+Function views
+ 1. Add an import: from my_app import views
+ 2. Add a URL to urlpatterns: path('', views.home, name='home')
+Class-based views
+ 1. Add an import: from other_app.views import Home
+ 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
+Including another URLconf
+ 1. Import the include() function: from django.urls import include, path
+ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
+"""
+from django.urls import path, include
+
+urlpatterns = [
+ path('account', include('account.urls')),
+ path('posting', include('posting.urls')),
+] | Python | ์ด ๋ถ๋ถ์ ์์ฝ๋ url ํจํด ์ปจ๋ฒค์
์ ๋ง์ง ์์ต๋๋ค. ์์ ๋ฆฌ๋ทฐ๋๋ฆฐ ๋ด์ฉ ์ค `/` ๊ด๋ จ ์ง๋ฌธ ๋จ๊ฒจ๋๋ ธ์ผ๋ ํ์ธํด์ฃผ์ธ์. |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | ๊น๋ํ๋ค์~! ๐ฏ |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | `json.loads()` ๋ ํธ๋คํด์ฃผ์
์ผํ๋ exception ์ด ๋ฐ์ํ ์ ์์ต๋๋ค. ํ์ธํด๋ณด์๊ณ ์ถ๊ฐํด์ฃผ์ธ์! |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | ๋ค๋ฏผ๋์ด ์์ฑํ์ ์ฝ๋ ๋ก์ง์ ์์๋๋ก ์ ๋ฆฌํด๋ณด๊ฒ ์ต๋๋ค.
1. `client` ์์ ๋ค์ด์จ `email`, `password` ๊ฐ์ ์ด์ฉํ์ฌ ์ผ์นํ๋ user ๋ฅผ filter ํ๋ ์ฟผ๋ฆฌ๋ฅผ ๋ ๋ ค user ๋ณ์์ ์ ์ฅํด์ค๋ค.
2. `email` ๋ก filter ์ฟผ๋ฆฌ๋ฅผ ๋ ๋ ค ์กด์ฌํ๋ user ์ธ์ง ํ์ธํ๋ค.
3. `password` ๋ก filter ์ฟผ๋ฆฌ๋ฅผ ๋ ๋ ค ์กด์ฌํ๋ user ์ธ์ง ํ์ธํ๋ค.
4. client ์์ ๋ค์ด์จ `email`, `password` ๊ฐ ์ ํจํ ํฌ๋งท์ธ์ง ๊ฒ์ฌํ์ฌ ์ ํจํ๋ค๋ฉด CREATE ๋ฅผ ์งํํ๋ค.
์ด๋ ๊ฒ ๋ง๋ก ์ ๋ฆฌํด๋ณด๋ ํ๋ฆ์ด ์ข ์ด์ํ์ง ์๋์?
์ด ๋ถ๋ถ์ ์ด๋ค ์์๋๋ก ์์ฑํ๋ฉด ์ข์์ง ์ ๊ฐ ํ๊ฒ์ฒ๋ผ ๊ธ๋ก ์ ๋ฆฌํด์ comment ๋จ๊ฒจ์ฃผ์ธ์. |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | ์ฌ๊ธฐ์ ์ ๊น ์ง๋ฌธ!
`KeyError` ์ด๋ค ์๋ฌ์ด๋ฉฐ, ์ธ์ ๋ฐ์ํ ๊น์? |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | SignupView ์ ๋น์ทํ ๋ก์ง ํ๋ฆ์ด๋ค์. ์์ชฝ ๋จ๊ฒจ๋๋ฆฐ ์ง๋ฌธ ๋จผ์ ํ์ธํด์ฃผ์ธ์! |
@@ -0,0 +1,17 @@
+from django.db import models
+
+class User(models.Model):
+ email = models.EmailField(max_length=50, unique=True)
+ password = models.CharField(max_length=100)
+ relation = models.ManyToManyField('self', through='Follow', symmetrical=False)
+
+ class Meta:
+ db_table = "users"
+
+
+class Follow(models.Model):
+ following = models.ForeignKey(User, on_delete = models.SET_NULL, null=True, related_name = "following")
+ follower = models.ForeignKey(User, on_delete = models.SET_NULL, null=True, related_name = "follower")
+
+ class Meta:
+ db_table = "follows"
\ No newline at end of file | Python | `from django.db import models
class User(models.Model):
email = models.EmailField(max_length=50, unique=True)` ๋ก ํด๊ฒฐํ์ต๋๋ค. |
@@ -0,0 +1,10 @@
+from django.urls import path
+from .views import SignupView, LoginView, FollowView
+
+urlpatterns = [
+ path('/user', SignupView.as_view()),
+ path('/login', LoginView.as_view()),
+ path('/follow', FollowView.as_view()),
+
+]
+'''Error๊ฐ ์๋๋ผ django์ ๊ถ์ฅ์ฌํญ. ํ์ง๋ง ํจํด ์ปจ๋ฒค์
์๋ ์ ์ฌํญ์ด ๋ง๋ค.''' | Python | `from django.urls import path
from .views import SignupView, LoginView` ๋ก ํ์ํ ๋ทฐ ํด๋์ค ๊ฐ์ ธ์ค๋ ๊ฒ์ผ๋ก ์์ ํ์์ต๋๋ค. |
@@ -0,0 +1,10 @@
+from django.urls import path
+from .views import SignupView, LoginView, FollowView
+
+urlpatterns = [
+ path('/user', SignupView.as_view()),
+ path('/login', LoginView.as_view()),
+ path('/follow', FollowView.as_view()),
+
+]
+'''Error๊ฐ ์๋๋ผ django์ ๊ถ์ฅ์ฌํญ. ํ์ง๋ง ํจํด ์ปจ๋ฒค์
์๋ ์ ์ฌํญ์ด ๋ง๋ค.''' | Python | Error๊ฐ ์๋๋ผ django์ ๊ถ์ฅ์ฌํญ์ด์ด์ ๊ทธ๋ ์ต๋๋ค. ํ์ง๋ง ํจํด ์ปจ๋ฒค์
์๋ ๊ณ ์ณ์ ์ฐ๋ ๊ฒ์ด ๋ง๊ธฐ ๋๋ฌธ์ ๊ณ ์ณค์ต๋๋ค. |
@@ -0,0 +1,21 @@
+"""westagram URL Configuration
+
+The `urlpatterns` list routes URLs to views. For more information please see:
+ https://docs.djangoproject.com/en/3.1/topics/http/urls/
+Examples:
+Function views
+ 1. Add an import: from my_app import views
+ 2. Add a URL to urlpatterns: path('', views.home, name='home')
+Class-based views
+ 1. Add an import: from other_app.views import Home
+ 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
+Including another URLconf
+ 1. Import the include() function: from django.urls import include, path
+ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
+"""
+from django.urls import path, include
+
+urlpatterns = [
+ path('account', include('account.urls')),
+ path('posting', include('posting.urls')),
+] | Python | ์์ ํ์์ต๋๋ค. |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | `class SignupView(View):
def post(self, request):
try:
data = json.loads(request.body)
user = User.objects.filter(email=data['email'],password=data['password'])`
์๋ ๋ก๊ทธ์ธ๋ทฐ๋ ๋๊ฐ์ ํํ๋ก ๋ฐ๊ฟจ์ต๋๋ค.
์ด์ : ์ฌ์ฉ์์๊ฒ ํ์์ ๋ฐ์ ๋ ๊ผญ ๋ด๊ฐ ์ํ๋ ํํ๋ก json์ด ์ค์ง ์์ ์ ์๊ธฐ์ Key-error ์ํฉ์ ์ค์ผ ํ๊ธฐ ๋๋ฌธ. |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | ์ด๊ฑฐ ํํฅ๋ํ๊ณ ์ด์ผ๊ธฐํ๋ค๊ฐ ์ ๊ฒ์ธ๋ฐ, ํค ์๋ฌ๋ ๋์
๋๋ฆฌ ํํ์์ ์์ฃผ ๋ฐ์ํ๋ฉฐ ๋์
๋๋ฆฌ ๋ด๋ถ์ ์กด์ฌํ์ง ์๋ ํค๋ฅผ ์ฌ์ฉํด์ ๊ฐ์ ๋ด๋ ค๊ณ ํ ๋ ๋๋ ์๋ฌ์
๋๋ค. ์ด๋ฒ ์์๋ก๋ ๋ง์ผ ๋ฐ์ดํฐ๊ฐ email=~~~ password=~~~ ๋ก ์ค๋ ๊ฒ์ด ์๋๋ผ emailadkfj=~~~ apsdkfjsa=~~~์ฒ๋ผ ํค ๋ด์ฉ์ด ์๋ชป ์๋ฒ๋ฆฌ๋ ๊ฒฝ์ฐ ์์ธ ์ฒ๋ฆฌ๋ก ํค ์๋ฌ๋ฅผ ๋ด๊ธฐ ์ํด ํ๋ ๊ฒ์ผ๋ก ์๋ํ๊ณ ํ์ต๋๋ค! |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | ํ์ธํ์ต๋๋ค |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | ๋จผ์ ๋ ํด๋์ค ๋ชจ๋ ๊ณตํต์ ์ผ๋ก user๋ผ๋ ๋ณ์๊ฐ ๋ถํ์ํด์ ์ง์ ์ต๋๋ค.
- ์ด์ : ์ด๋ฏธ User.~๋ฅผ ํตํด ์ฟผ๋ฆฌ๋ฅผ ๋ ๋ ค ๋ฐ์ดํฐ์์ ํ์ํ ์๋ฃ๋ฅผ ๊ฐ์ ธ์ฌ ์ ์๋ค. ๋ถํ์ํ ๋ณ์์๋ค.
- comment :
1. client์์ ๋ค์ด์จ ๊ฐ ์ค ์ด๋ฉ์ผ ํํฐ ์ฟผ๋ฆฌ๋ฅผ ๋ ๋ ค ์กด์ฌํ๋ ์ด๋ฉ์ผ์ผ ๊ฒฝ์ฐ์ธ์ง ํ์ธ.
2. (๋ง์ฐฌ๊ฐ์ง๋ก) ๋น๋ฐ๋ฒํธ ํํฐ ์ฟผ๋ฆฌ๋ฅผ ๋ ๋ ค ์กด์ฌํ๋ ๋น๋ฐ๋ฒํธ์ธ์ง ํ์ธ.
3. ์ด๋ฉ์ผ๊ณผ ๋น๋ฐ๋ฒํธ๊ฐ ์ ํจํ ํฌ๋งท์ธ์ง ๊ฒ์ฌํ์ฌ ์ ํจํ๋ฉด ๊ฐ ๋ง๋ค๊ธฐ ์งํ.
- ์์ง ์ฟผ๋ฆฌ๋ฅผ ๋ ๋ฆฐ๋ค๋ ๊ฐ๋
์ด ํ์คํ ์์ง ์์ ํํ์ด ๋ง๋๊ฑด์ง๋ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. ๋ฌธ๋ฒ์ ์ธ ์ ์ ๊ฒํ ํด์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค..! |
@@ -0,0 +1,17 @@
+from django.db import models
+
+class User(models.Model):
+ email = models.EmailField(max_length=50, unique=True)
+ password = models.CharField(max_length=100)
+ relation = models.ManyToManyField('self', through='Follow', symmetrical=False)
+
+ class Meta:
+ db_table = "users"
+
+
+class Follow(models.Model):
+ following = models.ForeignKey(User, on_delete = models.SET_NULL, null=True, related_name = "following")
+ follower = models.ForeignKey(User, on_delete = models.SET_NULL, null=True, related_name = "follower")
+
+ class Meta:
+ db_table = "follows"
\ No newline at end of file | Python | `unique=True` ๊ตณ์
๋๋ค!! |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | @damin0320 ์ ํํฉ๋๋ค ๋ค๋ฏผ๋! |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | ๊ฐ๋
์ฑ์ ์ํด ๋ก์ง๋ณ๋ก ๋ถ๋ฆฌํด์ ๋์ด์ฐ๊ธฐ๋ก ๊ตฌ๋ถํด์ฃผ์ธ์! ์ง๊ธ์ ๋๋ฌด ๋ค ๋ถ์ด์์ด์ ์ฝ๊ธฐ๊ฐ ์ข์ ์ฝ๋๊ฐ ์๋๋๋ค ๋ค๋ฏผ๋! |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | exists() ํ์ฉ gooood ๐ |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | ์ด ๋ถ๋ถ์ ๋ก์ง์ด ์กฐ๊ธ ์ด์ํ๋ฐ์.
password ๋ ๊ณ ์ ๊ฐ์ด ์๋๊ณ , ๊ฐ์ password ๋ฅผ ๊ฐ์ง ์ ์ ์ ๋ณด๋ค์ด ์ถฉ๋ถํ ์กด์ฌํ ์ ์๋๋ฐ password ๋ก ํํฐ๋ฅผ ๊ฑธ์ด์ค ํ์๋ ์๋ค๊ณ ์๊ฐํฉ๋๋ค~ |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | ์ํธํ ๊ณผ์ ์ ์ฉ ์ ๋ง ์ํ์
จ์ต๋๋ค! |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | create() ๋ค์ save() ๋ ๋ถํ์ํฉ๋๋ค ๋ค๋ฏผ๋. ์์ ์ฃผ์ธ์! |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | get() ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์๋ฉด ๊ผญ ์ก์์ฃผ์
์ผํ๋ exception ๋ค์ด ์์ต๋๋ค.
์์๋ณด์๊ณ exception handling ๋ก์ง์ ์ถ๊ฐํด์ฃผ์ธ์! |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | ์ฌ๊ธฐ๋ ๋ง์ฐฌ๊ฐ์ง๋ก ๊ฐ๋
์ฑ์ ์ํด ๋ก์ง์ ๋ธ๋ก์ผ๋ก ๊ตฌ๋ถํ์ฌ ํ์ค์ฉ ์ถ๊ฐํด์ฃผ์ธ์! |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | ์ด์ผ~ jwt ์์ฑ ๋ก์ง๊น์ง ๋๋ฌด ์ ์ ์ฉํ์
จ๋ค์!
ํ์ง๋ง ์์ฑ์ ์๋ฃํ๋๋ฐ ์์ฑ๋งํ๊ณ ์ฌ์ฉ์ ์ํ๊ณ ๊ณ์๋ค์. ๋ค์ ์คํ
์ ๋ฌด์์ผ๊น์? |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | ์ฌ๊ธฐ์ ์ด๋ ๊ฒ else ๋ก ์ก์์ฃผ์๊ธฐ ๋ณด๋ค๋ checkpw() ์ ๊ฐ์ด Falsy ํ๋ค๋ฉด 401 ์ ๋ฆฌํดํด์ฃผ์๊ณ ,
๋์ด์์ ์ง๊ธ ์์ ๋ณด์๋ If ๋ฌธ์ ๋ก์ง์ ์ฒ๋ฆฌํด์ฃผ์ ๋ค๋ฉด ๋ถํ์ํ else ๋ฌธ์ด ์์ด์ง๊ฒ ์ฃ ? |
@@ -0,0 +1,103 @@
+import json
+import bcrypt
+import jwt
+
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User, Follow
+from my_settings import SECRET_KEY
+
+class SignupView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ if User.objects.filter(email=data['email']).exists():
+ return JsonResponse({"message": "EMAIL_ERROR"}, status=400)
+
+ if not '@' in data['email'] or not '.' in data['email']:
+ return JsonResponse({"message":"EMAIL_FAIL"}, status=400)
+ if len(data['password']) < 8:
+ return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400)
+
+ byted_password = data['password'].encode('utf-8')
+ hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode()
+ password = hash_password
+ user = User.objects.create(
+ email = data['email'],
+ password = password
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ except KeyError:
+ return JsonResponse({"message": "KEY_ERROR"}, status=400)
+
+
+class LoginView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ try:
+ user = User.objects.get(email=data['email'])
+ # user๋ ๊ฐ์ฒด๋ค
+ user_id = user.id
+ # ๊ฐ์ฒด์ .~ํ๋ฉด ๋ฐ๋ก ๋ด์ฉ์ ๊บผ๋ผ ์ ์๋ค.
+ except User.DoesNotExist:
+ return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400)
+
+ if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')):
+ token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256")
+ # ์ ์ id๋ฅผ ํ ํฐ ๋ด์ฉ๋ฌผ์ ๋ฃ๋๋ค. ์ด๋ ์ด๋ฏธ ์ซ์๊ฐ ๋์์ผ๋ฏ๋ก data๋ก ํ ํ์ ์์
+ return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200)
+
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+
+class TokenCheckView(View):
+ def post(self,request):
+ data = json.loads(request.body)
+
+ user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256')
+
+ if User.objects.filter(email=user_token_info['email']).exists():
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+class FollowView(View):
+ def post(self, request):
+ data = json.loads(request.body)
+ following = User.objects.get(email=data['following'])
+ follower = User.objects.get(email=data['follower'])
+ if following == follower:
+ return JsonResponse({"message":"SAME_PERSON!"})
+ follow = Follow.objects.create(
+ following = following,
+ follower = follower
+ )
+ return JsonResponse({"message": "SUCCESS"}, status=200)
+
+def TokenCheck(func):
+ def wrapper(self, request, *args, **kwargs):
+ # ๋ฆฌํ์คํธํด์ ํ ํฐ ๊น๋ ์
+ # ํ ํฐ์ ํต์ฌ์ ๊ณต๊ฐ๊ฐ ๋์ด๋ ๋๋ค -> ๊ทธ๋์ ์์ ๊ฐ user_id์๋ ๊ฒ.
+ try:
+ token = request.headers.get('Authorization')
+ if token:
+ payload = jwt.decode(token, SECRET_KEY, algorithms="HS256")
+ user_id = payload['user_id']
+ user = User.objects.get(id=user_id)
+ # user_id ๊ฐ์ ธ์จ ๊ฒ์ user๋ผ๋ ๋ณ์์ ๋ด๊ณ
+
+ request.user = user
+ # ๋ณ์์ ๋ด์ ๊ฒ์ ๋ค์์ ๋ถ๋ฅผ request.user์ ๋ ๋ด์์ค๋ค.
+ return func(self, request, *args, **kwargs)
+ # ์๋ returnํ๋ฉด์ request๋ฅผ posting์์ ์ฌ์ฉํ ์์ (.user ๋ง ๋ถ์ด๋ฉด ์ด์ ์๋ ์์ฑ)
+ return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400)
+ except jwt.InvalidTokenError:
+ return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400)
+
+ # ์ง๊ธ์ ์ซ์๋ง ํ์ธ ์ํฉ(id๊ฐ๋ง ๋ฐ์์ ํ์ธํ ์ํฉ)
+ # ์ถ๊ฐ : ํ ํฐ์ ๋ค์ ์ ๊ฐ๋ค์ค ์ํฉ(๋ฆฌํ์คํธ์ ์ ๋ณด๋ฅผ ๋ฃ์ด์ค๋ค.) ; ๋ฆฌํ์คํธ์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค์ด์ค๋ค.(์์ด๋๊ฐ์ ๋ฃ์ด์ค๋ค.->์ด๊ฑธ ๊บผ๋ด ์ด๋ค.)
+
+ return wrapper
\ No newline at end of file | Python | ํ ํฐ์์ ์ ์ ์ ๋ณด๋ฅผ ์ฐพ์์์ ํํฐํ๋ ๊ธฐ๋ฅ๊น์ง! ๐ ๐ ๐
๋ค๋ฏผ๋ ์ฒ์์๋ ์ดํดํ๋๋ฐ ์ด๋ ค์ํ์๋ ๊ฒ ๊ฐ์ ๊ฑฑ์ ์ ์กฐ๊ธ ํ์๋๋ฐ, ์ง๊ธ๋ณด๋ฉด ๋ฌธ์ ํด๊ฒฐ๋ฅ๋ ฅ์ด ์ ๋ง ์ข์ผ์ ๊ฒ ๊ฐ์์! ๋๋ฌด ์ํ์
จ์ต๋๋คใ
ใ
|
@@ -0,0 +1,12 @@
+from django.db import models
+
+class User(models.Model):
+
+ email = models.EmailField(max_length=50, unique=True)
+ name = models.CharField(max_length=50, unique=True)
+ phone = models.CharField(max_length=50, unique=True)
+ password= models.CharField(max_length=500)
+
+ class Meta:
+ db_table='users'
+ | Python | - email ์ ๊ฐ๋
์ฑ์ ์ํด, ๊ทธ๋ฆฌ๊ณ ์ถํ ์ฅ๊ณ Form ์ด ์ ๊ณตํ๋ validator ๋ฅผ ์ฌ์ฉํ ์๋ ์์ ๊ฒ์ ๊ฐ์ํด์ EmailField ๋ก ์ ์ธํด์ฃผ์ธ์!
- ๊ทธ๋ฆฌ๊ณ email ์ ๊ณ ์ ๊ฐ์ด์ฃ ? ์ด๋ด๋ ์ถ๊ฐํด์ค ์ ์๋ ์ต์
์ด ์์ต๋๋ค! ์ฐพ์์ ์ถ๊ฐํด์ฃผ์ธ์~ |
@@ -0,0 +1,12 @@
+from django.db import models
+
+class User(models.Model):
+
+ email = models.EmailField(max_length=50, unique=True)
+ name = models.CharField(max_length=50, unique=True)
+ phone = models.CharField(max_length=50, unique=True)
+ password= models.CharField(max_length=500)
+
+ class Meta:
+ db_table='users'
+ | Python | ๋ณดํต ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ปฌ๋ผ๋ช
์ ์ค์ฌ์ฐ์ง์๊ณ ์ต๋ํ ๋ช
ํํ๊ฒ ํ์ด์ ์ ์ธํด์ค๋๋ค. ์ฌ๊ธฐ๋ password ๋ก ํ์ด์ฃผ์ธ์~
๊ทธ๋ฆฌ๊ณ ์ด์ ๋น๋ฐ๋ฒํธ ์ํธํ ๊ณผ์ ์ ์งํํ๋๋งํผ ์ต๋ ๊ธ์์๋ฅผ ์กฐ๊ธ ๋ ๋๋ํ๊ฒ ์ก์์ฃผ์๋๊ฒ ์ข์ต๋๋ค! |
@@ -0,0 +1,76 @@
+import json,bcrypt,jwt
+from json.decoder import JSONDecodeError
+
+from django.db.models import Q
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User
+from my_settings import SECRET_KEY, ALGORITHM
+
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ name = data['name']
+ email = data['email']
+ phone = data['phone']
+ password= data['password']
+
+ if '.' not in email or '@' not in email:
+ return JsonResponse({'message':'error_email_form'}, status=401)
+
+ if len(password)<8:
+ return JsonResponse({'message':'error_password_form'}, status=401)
+
+ if User.objects.filter(Q(name=name) | Q(email=email) | Q(phone=phone)).exists:
+ return JsonResponse({'message':'id_exist'}, status = 401)
+
+ hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
+ decoded_password= hashed_password.decode('utf-8')
+
+ User.objects.create(email=email, name=name, phone=phone, password=decoded_password)
+ return JsonResponse({'message':'success_signup'}, status = 201)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ id = data['id']
+ password= data['password']
+ user = User.objects.get(Q(name=id) | Q(email=id) | Q(phone=id))
+
+ if user is not id:
+ return JsonResponse({'message':'error_id_matching'}, status=401)
+
+ if user is id:
+ decoded_password = user.password
+ encoded_password = password.encode('utf-8')
+ bcrypt.checkpw(encoded_password, decoded_password.encode('utf-8'))
+ token = jwt.encode({'user':user.id}, SECRET_KEY, ALGORITHM)
+ return JsonResponse({'message':'success_signin', 'access_token':token}, status=201)
+
+ return JsonResponse({'message':'error_password_matching'}, status = 401)
+
+ except User.MultipleObjectsReturned:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except User.DoesNotExist:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+ | Python | - exists ๋ฉ์๋ ๋๋ฌด ์ ํ์ฉํ์
จ๋ค์!! ๐
- ์ฌ๊ธฐ์ exists ์ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ๋ก ๋ณ์์ ์ ์ฅํด์ค๊ฒ ์์ด ์๋ if ๋ฌธ์ ๋ฐ๋ก ์ ์ฉํด์ฃผ์ ๋ค๋ฉด ๋ถํ์ํ ๋ณ์ ์ ์ธ์ ์์จ ์ ์๊ฒ ์ฃ ?! |
@@ -0,0 +1,76 @@
+import json,bcrypt,jwt
+from json.decoder import JSONDecodeError
+
+from django.db.models import Q
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User
+from my_settings import SECRET_KEY, ALGORITHM
+
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ name = data['name']
+ email = data['email']
+ phone = data['phone']
+ password= data['password']
+
+ if '.' not in email or '@' not in email:
+ return JsonResponse({'message':'error_email_form'}, status=401)
+
+ if len(password)<8:
+ return JsonResponse({'message':'error_password_form'}, status=401)
+
+ if User.objects.filter(Q(name=name) | Q(email=email) | Q(phone=phone)).exists:
+ return JsonResponse({'message':'id_exist'}, status = 401)
+
+ hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
+ decoded_password= hashed_password.decode('utf-8')
+
+ User.objects.create(email=email, name=name, phone=phone, password=decoded_password)
+ return JsonResponse({'message':'success_signup'}, status = 201)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ id = data['id']
+ password= data['password']
+ user = User.objects.get(Q(name=id) | Q(email=id) | Q(phone=id))
+
+ if user is not id:
+ return JsonResponse({'message':'error_id_matching'}, status=401)
+
+ if user is id:
+ decoded_password = user.password
+ encoded_password = password.encode('utf-8')
+ bcrypt.checkpw(encoded_password, decoded_password.encode('utf-8'))
+ token = jwt.encode({'user':user.id}, SECRET_KEY, ALGORITHM)
+ return JsonResponse({'message':'success_signin', 'access_token':token}, status=201)
+
+ return JsonResponse({'message':'error_password_matching'}, status = 401)
+
+ except User.MultipleObjectsReturned:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except User.DoesNotExist:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+ | Python | or, not, in ํ์ฉ ๋๋ฌด ์ข์ต๋๋ค ํธ์ด๋!!! ๊ทธ๋ฐ๋ฐ email ์ list ๋ก ํ๋ณํํด์ฃผ์ ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,76 @@
+import json,bcrypt,jwt
+from json.decoder import JSONDecodeError
+
+from django.db.models import Q
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User
+from my_settings import SECRET_KEY, ALGORITHM
+
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ name = data['name']
+ email = data['email']
+ phone = data['phone']
+ password= data['password']
+
+ if '.' not in email or '@' not in email:
+ return JsonResponse({'message':'error_email_form'}, status=401)
+
+ if len(password)<8:
+ return JsonResponse({'message':'error_password_form'}, status=401)
+
+ if User.objects.filter(Q(name=name) | Q(email=email) | Q(phone=phone)).exists:
+ return JsonResponse({'message':'id_exist'}, status = 401)
+
+ hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
+ decoded_password= hashed_password.decode('utf-8')
+
+ User.objects.create(email=email, name=name, phone=phone, password=decoded_password)
+ return JsonResponse({'message':'success_signup'}, status = 201)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ id = data['id']
+ password= data['password']
+ user = User.objects.get(Q(name=id) | Q(email=id) | Q(phone=id))
+
+ if user is not id:
+ return JsonResponse({'message':'error_id_matching'}, status=401)
+
+ if user is id:
+ decoded_password = user.password
+ encoded_password = password.encode('utf-8')
+ bcrypt.checkpw(encoded_password, decoded_password.encode('utf-8'))
+ token = jwt.encode({'user':user.id}, SECRET_KEY, ALGORITHM)
+ return JsonResponse({'message':'success_signin', 'access_token':token}, status=201)
+
+ return JsonResponse({'message':'error_password_matching'}, status = 401)
+
+ except User.MultipleObjectsReturned:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except User.DoesNotExist:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+ | Python | ์์ ๋ฆฌ๋ทฐ ๋ด์ฉ ๋ฐ์ํด์ฃผ์๋ฉด ์ด ๋ถ๋ถ์ ์์ ์ฌํญ์ด ์๊ธฐ๊ฒ ์ฃ !? |
@@ -0,0 +1,76 @@
+import json,bcrypt,jwt
+from json.decoder import JSONDecodeError
+
+from django.db.models import Q
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User
+from my_settings import SECRET_KEY, ALGORITHM
+
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ name = data['name']
+ email = data['email']
+ phone = data['phone']
+ password= data['password']
+
+ if '.' not in email or '@' not in email:
+ return JsonResponse({'message':'error_email_form'}, status=401)
+
+ if len(password)<8:
+ return JsonResponse({'message':'error_password_form'}, status=401)
+
+ if User.objects.filter(Q(name=name) | Q(email=email) | Q(phone=phone)).exists:
+ return JsonResponse({'message':'id_exist'}, status = 401)
+
+ hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
+ decoded_password= hashed_password.decode('utf-8')
+
+ User.objects.create(email=email, name=name, phone=phone, password=decoded_password)
+ return JsonResponse({'message':'success_signup'}, status = 201)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ id = data['id']
+ password= data['password']
+ user = User.objects.get(Q(name=id) | Q(email=id) | Q(phone=id))
+
+ if user is not id:
+ return JsonResponse({'message':'error_id_matching'}, status=401)
+
+ if user is id:
+ decoded_password = user.password
+ encoded_password = password.encode('utf-8')
+ bcrypt.checkpw(encoded_password, decoded_password.encode('utf-8'))
+ token = jwt.encode({'user':user.id}, SECRET_KEY, ALGORITHM)
+ return JsonResponse({'message':'success_signin', 'access_token':token}, status=201)
+
+ return JsonResponse({'message':'error_password_matching'}, status = 401)
+
+ except User.MultipleObjectsReturned:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except User.DoesNotExist:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+ | Python | `or` ๊ณผ `is` ์ค์ ์ด๋ค๊ฒ ์ฐ์ ์์์ผ๊น์? ์กฐ๊ฑด๋ฌธ์์ operator precedence ์ ๋ฐ๋ผ ์กฐ๊ฑด์ด ์์ ํ ๋ฐ๋ ์ ์๊ธฐ ๋๋ฌธ์ ์ ํ์
ํ๊ณ ์ฌ์ฉํ์๋๊ฒ ์ข์ต๋๋ค! |
@@ -0,0 +1,76 @@
+import json,bcrypt,jwt
+from json.decoder import JSONDecodeError
+
+from django.db.models import Q
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User
+from my_settings import SECRET_KEY, ALGORITHM
+
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ name = data['name']
+ email = data['email']
+ phone = data['phone']
+ password= data['password']
+
+ if '.' not in email or '@' not in email:
+ return JsonResponse({'message':'error_email_form'}, status=401)
+
+ if len(password)<8:
+ return JsonResponse({'message':'error_password_form'}, status=401)
+
+ if User.objects.filter(Q(name=name) | Q(email=email) | Q(phone=phone)).exists:
+ return JsonResponse({'message':'id_exist'}, status = 401)
+
+ hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
+ decoded_password= hashed_password.decode('utf-8')
+
+ User.objects.create(email=email, name=name, phone=phone, password=decoded_password)
+ return JsonResponse({'message':'success_signup'}, status = 201)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ id = data['id']
+ password= data['password']
+ user = User.objects.get(Q(name=id) | Q(email=id) | Q(phone=id))
+
+ if user is not id:
+ return JsonResponse({'message':'error_id_matching'}, status=401)
+
+ if user is id:
+ decoded_password = user.password
+ encoded_password = password.encode('utf-8')
+ bcrypt.checkpw(encoded_password, decoded_password.encode('utf-8'))
+ token = jwt.encode({'user':user.id}, SECRET_KEY, ALGORITHM)
+ return JsonResponse({'message':'success_signin', 'access_token':token}, status=201)
+
+ return JsonResponse({'message':'error_password_matching'}, status = 401)
+
+ except User.MultipleObjectsReturned:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except User.DoesNotExist:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+ | Python | ์ด ๋ถ๋ถ๋ค์์๋ ํ์ด์ฌ์ exception ์ด ๋ฐ์ํ ์ ์์ต๋๋ค. Exception handling ์ ๋ํด์ repl.it ์์ ๋ณด์ ์ ์ด ์์ผ์ ๋ฐ์! ์ค์ ๋ก view ์์ ์ ๋ง์ ๋ง ์ค์ํ ์ญํ ์ ํ๋ ๋งํผ ๊ผญ ์ถ๊ฐ๋์ด์ผ ํ๋ ๋ก์ง์
๋๋ค.
์ด ์ฝ๋๋ค์์ ์ด๋ค exception ์ด ๋ฐ์ํ ์ ์์์ง ํ์ธํด๋ณด์๊ณ ํธ๋ค๋ง ๋ก์ง ์ถ๊ฐํด์ฃผ์ธ์! |
@@ -0,0 +1,76 @@
+import json,bcrypt,jwt
+from json.decoder import JSONDecodeError
+
+from django.db.models import Q
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User
+from my_settings import SECRET_KEY, ALGORITHM
+
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ name = data['name']
+ email = data['email']
+ phone = data['phone']
+ password= data['password']
+
+ if '.' not in email or '@' not in email:
+ return JsonResponse({'message':'error_email_form'}, status=401)
+
+ if len(password)<8:
+ return JsonResponse({'message':'error_password_form'}, status=401)
+
+ if User.objects.filter(Q(name=name) | Q(email=email) | Q(phone=phone)).exists:
+ return JsonResponse({'message':'id_exist'}, status = 401)
+
+ hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
+ decoded_password= hashed_password.decode('utf-8')
+
+ User.objects.create(email=email, name=name, phone=phone, password=decoded_password)
+ return JsonResponse({'message':'success_signup'}, status = 201)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ id = data['id']
+ password= data['password']
+ user = User.objects.get(Q(name=id) | Q(email=id) | Q(phone=id))
+
+ if user is not id:
+ return JsonResponse({'message':'error_id_matching'}, status=401)
+
+ if user is id:
+ decoded_password = user.password
+ encoded_password = password.encode('utf-8')
+ bcrypt.checkpw(encoded_password, decoded_password.encode('utf-8'))
+ token = jwt.encode({'user':user.id}, SECRET_KEY, ALGORITHM)
+ return JsonResponse({'message':'success_signin', 'access_token':token}, status=201)
+
+ return JsonResponse({'message':'error_password_matching'}, status = 401)
+
+ except User.MultipleObjectsReturned:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except User.DoesNotExist:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+ | Python | ์ด์ bcrypt ๋ฅผ ํ์ฉํ์ฌ ๋น๋ฐ๋ฒํธ ์ํธํ ๋ก์ง ์ถ๊ฐํด์ ์ ์ฅํด์ฃผ์ธ์! |
@@ -0,0 +1,76 @@
+import json,bcrypt,jwt
+from json.decoder import JSONDecodeError
+
+from django.db.models import Q
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User
+from my_settings import SECRET_KEY, ALGORITHM
+
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ name = data['name']
+ email = data['email']
+ phone = data['phone']
+ password= data['password']
+
+ if '.' not in email or '@' not in email:
+ return JsonResponse({'message':'error_email_form'}, status=401)
+
+ if len(password)<8:
+ return JsonResponse({'message':'error_password_form'}, status=401)
+
+ if User.objects.filter(Q(name=name) | Q(email=email) | Q(phone=phone)).exists:
+ return JsonResponse({'message':'id_exist'}, status = 401)
+
+ hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
+ decoded_password= hashed_password.decode('utf-8')
+
+ User.objects.create(email=email, name=name, phone=phone, password=decoded_password)
+ return JsonResponse({'message':'success_signup'}, status = 201)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ id = data['id']
+ password= data['password']
+ user = User.objects.get(Q(name=id) | Q(email=id) | Q(phone=id))
+
+ if user is not id:
+ return JsonResponse({'message':'error_id_matching'}, status=401)
+
+ if user is id:
+ decoded_password = user.password
+ encoded_password = password.encode('utf-8')
+ bcrypt.checkpw(encoded_password, decoded_password.encode('utf-8'))
+ token = jwt.encode({'user':user.id}, SECRET_KEY, ALGORITHM)
+ return JsonResponse({'message':'success_signin', 'access_token':token}, status=201)
+
+ return JsonResponse({'message':'error_password_matching'}, status = 401)
+
+ except User.MultipleObjectsReturned:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except User.DoesNotExist:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+ | Python | CREATED ๋ฅผ ์๋ฏธํ๋ 201 ์ฌ์ฉ ๋๋ฌด ์ํ์
จ์ต๋๋ค! ๐ |
@@ -0,0 +1,12 @@
+from django.db import models
+
+class User(models.Model):
+
+ email = models.EmailField(max_length=50, unique=True)
+ name = models.CharField(max_length=50, unique=True)
+ phone = models.CharField(max_length=50, unique=True)
+ password= models.CharField(max_length=500)
+
+ class Meta:
+ db_table='users'
+ | Python | ํด๋ํฐ ๋ฒํธ๋ ๊ณ ์ ๊ฐ์ด๋ ์์ฒ๋ผ ๊ณ ์ ๊ฐ์ ๋ปํ๋ ์ต์
์ ์ถ๊ฐํด์ฃผ์
์ผ ํฉ๋๋ค! |
@@ -0,0 +1,76 @@
+import json,bcrypt,jwt
+from json.decoder import JSONDecodeError
+
+from django.db.models import Q
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User
+from my_settings import SECRET_KEY, ALGORITHM
+
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ name = data['name']
+ email = data['email']
+ phone = data['phone']
+ password= data['password']
+
+ if '.' not in email or '@' not in email:
+ return JsonResponse({'message':'error_email_form'}, status=401)
+
+ if len(password)<8:
+ return JsonResponse({'message':'error_password_form'}, status=401)
+
+ if User.objects.filter(Q(name=name) | Q(email=email) | Q(phone=phone)).exists:
+ return JsonResponse({'message':'id_exist'}, status = 401)
+
+ hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
+ decoded_password= hashed_password.decode('utf-8')
+
+ User.objects.create(email=email, name=name, phone=phone, password=decoded_password)
+ return JsonResponse({'message':'success_signup'}, status = 201)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ id = data['id']
+ password= data['password']
+ user = User.objects.get(Q(name=id) | Q(email=id) | Q(phone=id))
+
+ if user is not id:
+ return JsonResponse({'message':'error_id_matching'}, status=401)
+
+ if user is id:
+ decoded_password = user.password
+ encoded_password = password.encode('utf-8')
+ bcrypt.checkpw(encoded_password, decoded_password.encode('utf-8'))
+ token = jwt.encode({'user':user.id}, SECRET_KEY, ALGORITHM)
+ return JsonResponse({'message':'success_signin', 'access_token':token}, status=201)
+
+ return JsonResponse({'message':'error_password_matching'}, status = 401)
+
+ except User.MultipleObjectsReturned:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except User.DoesNotExist:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+ | Python | string / list ์ ๋ํ ์ดํด๊ฐ ๋ถ์กฑํ์ต๋๋ค.
- [x] Strings can be indexed (subscripted), with the first character having index 0. There is no separate character type; a character is simply a string of size one:
- [x] if '.' not in email or '@' not in email: |
@@ -0,0 +1,76 @@
+import json,bcrypt,jwt
+from json.decoder import JSONDecodeError
+
+from django.db.models import Q
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User
+from my_settings import SECRET_KEY, ALGORITHM
+
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ name = data['name']
+ email = data['email']
+ phone = data['phone']
+ password= data['password']
+
+ if '.' not in email or '@' not in email:
+ return JsonResponse({'message':'error_email_form'}, status=401)
+
+ if len(password)<8:
+ return JsonResponse({'message':'error_password_form'}, status=401)
+
+ if User.objects.filter(Q(name=name) | Q(email=email) | Q(phone=phone)).exists:
+ return JsonResponse({'message':'id_exist'}, status = 401)
+
+ hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
+ decoded_password= hashed_password.decode('utf-8')
+
+ User.objects.create(email=email, name=name, phone=phone, password=decoded_password)
+ return JsonResponse({'message':'success_signup'}, status = 201)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ id = data['id']
+ password= data['password']
+ user = User.objects.get(Q(name=id) | Q(email=id) | Q(phone=id))
+
+ if user is not id:
+ return JsonResponse({'message':'error_id_matching'}, status=401)
+
+ if user is id:
+ decoded_password = user.password
+ encoded_password = password.encode('utf-8')
+ bcrypt.checkpw(encoded_password, decoded_password.encode('utf-8'))
+ token = jwt.encode({'user':user.id}, SECRET_KEY, ALGORITHM)
+ return JsonResponse({'message':'success_signin', 'access_token':token}, status=201)
+
+ return JsonResponse({'message':'error_password_matching'}, status = 401)
+
+ except User.MultipleObjectsReturned:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except User.DoesNotExist:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+ | Python | ๋ถํ์ํ ์ฃผ์ ์ ์ธํ๊ณ ์ฌ๋ ค์ฃผ์ธ์. |
@@ -0,0 +1,76 @@
+import json,bcrypt,jwt
+from json.decoder import JSONDecodeError
+
+from django.db.models import Q
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User
+from my_settings import SECRET_KEY, ALGORITHM
+
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ name = data['name']
+ email = data['email']
+ phone = data['phone']
+ password= data['password']
+
+ if '.' not in email or '@' not in email:
+ return JsonResponse({'message':'error_email_form'}, status=401)
+
+ if len(password)<8:
+ return JsonResponse({'message':'error_password_form'}, status=401)
+
+ if User.objects.filter(Q(name=name) | Q(email=email) | Q(phone=phone)).exists:
+ return JsonResponse({'message':'id_exist'}, status = 401)
+
+ hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
+ decoded_password= hashed_password.decode('utf-8')
+
+ User.objects.create(email=email, name=name, phone=phone, password=decoded_password)
+ return JsonResponse({'message':'success_signup'}, status = 201)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ id = data['id']
+ password= data['password']
+ user = User.objects.get(Q(name=id) | Q(email=id) | Q(phone=id))
+
+ if user is not id:
+ return JsonResponse({'message':'error_id_matching'}, status=401)
+
+ if user is id:
+ decoded_password = user.password
+ encoded_password = password.encode('utf-8')
+ bcrypt.checkpw(encoded_password, decoded_password.encode('utf-8'))
+ token = jwt.encode({'user':user.id}, SECRET_KEY, ALGORITHM)
+ return JsonResponse({'message':'success_signin', 'access_token':token}, status=201)
+
+ return JsonResponse({'message':'error_password_matching'}, status = 401)
+
+ except User.MultipleObjectsReturned:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except User.DoesNotExist:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+ | Python | else ๋ถํ์ |
@@ -0,0 +1,76 @@
+import json,bcrypt,jwt
+from json.decoder import JSONDecodeError
+
+from django.db.models import Q
+from django.views import View
+from django.http import JsonResponse
+
+from .models import User
+from my_settings import SECRET_KEY, ALGORITHM
+
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ name = data['name']
+ email = data['email']
+ phone = data['phone']
+ password= data['password']
+
+ if '.' not in email or '@' not in email:
+ return JsonResponse({'message':'error_email_form'}, status=401)
+
+ if len(password)<8:
+ return JsonResponse({'message':'error_password_form'}, status=401)
+
+ if User.objects.filter(Q(name=name) | Q(email=email) | Q(phone=phone)).exists:
+ return JsonResponse({'message':'id_exist'}, status = 401)
+
+ hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
+ decoded_password= hashed_password.decode('utf-8')
+
+ User.objects.create(email=email, name=name, phone=phone, password=decoded_password)
+ return JsonResponse({'message':'success_signup'}, status = 201)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+ id = data['id']
+ password= data['password']
+ user = User.objects.get(Q(name=id) | Q(email=id) | Q(phone=id))
+
+ if user is not id:
+ return JsonResponse({'message':'error_id_matching'}, status=401)
+
+ if user is id:
+ decoded_password = user.password
+ encoded_password = password.encode('utf-8')
+ bcrypt.checkpw(encoded_password, decoded_password.encode('utf-8'))
+ token = jwt.encode({'user':user.id}, SECRET_KEY, ALGORITHM)
+ return JsonResponse({'message':'success_signin', 'access_token':token}, status=201)
+
+ return JsonResponse({'message':'error_password_matching'}, status = 401)
+
+ except User.MultipleObjectsReturned:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except User.DoesNotExist:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=401)
+
+ except KeyError:
+ return JsonResponse({'message': 'KEY_ERROR'}, status=400)
+
+ except JSONDecodeError:
+ return JsonResponse({'message': 'JSONDecodeError'}, status=400)
+
+
+ | Python | ์ฑ๊ณต ์ผ์ด์ค์์ ์ธ ๋ก์ง์ด๊ธฐ ๋๋ฌธ์ ์๋๋ก ์์น์์ผ์ฃผ์ธ์. |
@@ -0,0 +1,145 @@
+"""
+Django settings for westagram project.
+
+Generated by 'django-admin startproject' using Django 3.1.7.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/3.1/topics/settings/
+
+For the full list of settings and their values, see
+https://docs.djangoproject.com/en/3.1/ref/settings/
+"""
+
+from pathlib import Path
+from my_settings import SECRET_KEY, DATABASES
+
+# Build paths inside the project like this: BASE_DIR / 'subdir'.
+BASE_DIR = Path(__file__).resolve().parent.parent
+
+
+# Quick-start development settings - unsuitable for production
+# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = SECRET_KEY
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = True
+
+ALLOWED_HOSTS = ['*']
+
+
+# Application definition
+
+INSTALLED_APPS = [
+# 'django.contrib.admin',
+# 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.messages',
+ 'django.contrib.staticfiles',
+ 'corsheaders',
+ 'user',
+ 'posting'
+]
+
+MIDDLEWARE = [
+ 'django.middleware.security.SecurityMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.common.CommonMiddleware',
+# 'django.middleware.csrf.CsrfViewMiddleware',
+# 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
+ 'django.middleware.clickjacking.XFrameOptionsMiddleware',
+ 'corsheaders.middleware.CorsMiddleware',
+]
+
+ROOT_URLCONF = 'westagram.urls'
+
+TEMPLATES = [
+ {
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'DIRS': [],
+ 'APP_DIRS': True,
+ 'OPTIONS': {
+ 'context_processors': [
+ 'django.template.context_processors.debug',
+ 'django.template.context_processors.request',
+ 'django.contrib.auth.context_processors.auth',
+ 'django.contrib.messages.context_processors.messages',
+ ],
+ },
+ },
+]
+
+WSGI_APPLICATION = 'westagram.wsgi.application'
+
+
+# Database
+# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
+
+DATABASES = DATABASES
+
+
+# Password validation
+# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
+
+AUTH_PASSWORD_VALIDATORS = [
+ {
+ 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
+ },
+]
+
+
+# Internationalization
+# https://docs.djangoproject.com/en/3.1/topics/i18n/
+
+LANGUAGE_CODE = 'en-us'
+
+TIME_ZONE = 'UTC'
+
+USE_I18N = True
+
+USE_L10N = True
+
+USE_TZ = True
+
+
+# Static files (CSS, JavaScript, Images)
+# https://docs.djangoproject.com/en/3.1/howto/static-files/
+
+STATIC_URL = '/static/'
+
+##CORS
+CORS_ORIGIN_ALLOW_ALL=True
+CORS_ALLOW_CREDENTIALS = True
+
+CORS_ALLOW_METHODS = (
+ 'DELETE',
+ 'GET',
+ 'OPTIONS',
+ 'PATCH',
+ 'POST',
+ 'PUT',
+)
+
+CORS_ALLOW_HEADERS = (
+ 'accept',
+ 'accept-encoding',
+ 'authorization',
+ 'content-type',
+ 'dnt',
+ 'origin',
+ 'user-agent',
+ 'x-csrftoken',
+ 'x-requested-with',
+) | Python | ์๋ฒฝํฉ๋๋ค ๊ตญํ๋! ๐ฏ |
@@ -0,0 +1,145 @@
+"""
+Django settings for westagram project.
+
+Generated by 'django-admin startproject' using Django 3.1.7.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/3.1/topics/settings/
+
+For the full list of settings and their values, see
+https://docs.djangoproject.com/en/3.1/ref/settings/
+"""
+
+from pathlib import Path
+from my_settings import SECRET_KEY, DATABASES
+
+# Build paths inside the project like this: BASE_DIR / 'subdir'.
+BASE_DIR = Path(__file__).resolve().parent.parent
+
+
+# Quick-start development settings - unsuitable for production
+# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = SECRET_KEY
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = True
+
+ALLOWED_HOSTS = ['*']
+
+
+# Application definition
+
+INSTALLED_APPS = [
+# 'django.contrib.admin',
+# 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.messages',
+ 'django.contrib.staticfiles',
+ 'corsheaders',
+ 'user',
+ 'posting'
+]
+
+MIDDLEWARE = [
+ 'django.middleware.security.SecurityMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.common.CommonMiddleware',
+# 'django.middleware.csrf.CsrfViewMiddleware',
+# 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
+ 'django.middleware.clickjacking.XFrameOptionsMiddleware',
+ 'corsheaders.middleware.CorsMiddleware',
+]
+
+ROOT_URLCONF = 'westagram.urls'
+
+TEMPLATES = [
+ {
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'DIRS': [],
+ 'APP_DIRS': True,
+ 'OPTIONS': {
+ 'context_processors': [
+ 'django.template.context_processors.debug',
+ 'django.template.context_processors.request',
+ 'django.contrib.auth.context_processors.auth',
+ 'django.contrib.messages.context_processors.messages',
+ ],
+ },
+ },
+]
+
+WSGI_APPLICATION = 'westagram.wsgi.application'
+
+
+# Database
+# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
+
+DATABASES = DATABASES
+
+
+# Password validation
+# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
+
+AUTH_PASSWORD_VALIDATORS = [
+ {
+ 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
+ },
+]
+
+
+# Internationalization
+# https://docs.djangoproject.com/en/3.1/topics/i18n/
+
+LANGUAGE_CODE = 'en-us'
+
+TIME_ZONE = 'UTC'
+
+USE_I18N = True
+
+USE_L10N = True
+
+USE_TZ = True
+
+
+# Static files (CSS, JavaScript, Images)
+# https://docs.djangoproject.com/en/3.1/howto/static-files/
+
+STATIC_URL = '/static/'
+
+##CORS
+CORS_ORIGIN_ALLOW_ALL=True
+CORS_ALLOW_CREDENTIALS = True
+
+CORS_ALLOW_METHODS = (
+ 'DELETE',
+ 'GET',
+ 'OPTIONS',
+ 'PATCH',
+ 'POST',
+ 'PUT',
+)
+
+CORS_ALLOW_HEADERS = (
+ 'accept',
+ 'accept-encoding',
+ 'authorization',
+ 'content-type',
+ 'dnt',
+ 'origin',
+ 'user-agent',
+ 'x-csrftoken',
+ 'x-requested-with',
+) | Python | ๋ต๋ต ํ์ธ ๊ฐ์ฌ๋๋ฆฝ๋๋ค ์นํ๋ ใ
ใ
๐๐
๋ฏธ์
2 ์งํํ๊ฒ ์ต๋๋ค~~~!!๐จโ๐ป |
@@ -0,0 +1,12 @@
+from django.db import models
+
+class User(models.Model):
+ email = models.EmailField(max_length=50, unique=True)
+ phone = models.CharField(max_length=11, null=True, unique=True)
+ full_name = models.CharField(max_length=40, null=True)
+ user_name = models.CharField(max_length=20, null=True, unique=True)
+ password = models.CharField(max_length=70)
+ date_of_birth = models.DateField(null=True)
+
+ class Meta:
+ db_table = 'users' | Python | ๋ถํ์ํ ์ฃผ์ ์์ ์ฃผ์ธ์! |
@@ -0,0 +1,12 @@
+from django.db import models
+
+class User(models.Model):
+ email = models.EmailField(max_length=50, unique=True)
+ phone = models.CharField(max_length=11, null=True, unique=True)
+ full_name = models.CharField(max_length=40, null=True)
+ user_name = models.CharField(max_length=20, null=True, unique=True)
+ password = models.CharField(max_length=70)
+ date_of_birth = models.DateField(null=True)
+
+ class Meta:
+ db_table = 'users' | Python | ์์ฑํ์ ์ฌ๋ฌ๊ฐ์ง ํ๋๋ค ์ค ์ค๋ณต์ ํ์ฉํ๋ฉด ์๋๋ ํ๋๋ค์ด ๋ณด์ด๋๋ฐ ๊ทธ๋ด๋ ์ฌ์ฉํ ์ ์๋ ์ต์
์ด ์์ต๋๋ค!
์ฐพ์์ ์ถ๊ฐํด์ฃผ์ธ์ ๐ |
@@ -0,0 +1,87 @@
+import re, json, bcrypt
+
+from django.views import View
+from django.http import JsonResponse, request
+from django.db.models.query_utils import Q
+from json.decoder import JSONDecodeError
+
+from user.utils import LoginCheck
+from user.models import User
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ email = data['email']
+ password = data['password']
+ phone = data.get('phone', None)
+ full_name = data.get('full_name', None)
+ user_name = data.get('user_name', None)
+ date_of_birth = data.get('date_of_birth', None)
+
+ if phone:
+ phone = phone.replace('-','')
+
+ REGEX_EMAIL = '^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
+ REGEX_PASSWORD = '\S{8,20}'
+
+ if not re.match(REGEX_EMAIL,email):
+ return JsonResponse({'message':'EMAIL VALIDATION ERROR'}, status=400)
+ if not re.match(REGEX_PASSWORD,password):
+ return JsonResponse({'message':'PASSWORD VALIDATION ERROR'}, status=400)
+
+ if not User.objects.filter(email=email):
+ if phone and User.objects.filter(phone=phone):
+ return JsonResponse({'message':'PHONE ALREADY EXISTS'}, status=400)
+ elif user_name and User.objects.filter(user_name=user_name):
+ return JsonResponse({'message':'USER_NAME ALREADY EXISTS'}, status=400)
+ else:
+ return JsonResponse({'message':'EMAIL ALREADY EXISTS'}, status=400)
+
+ hashed_password = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt()).decode()
+
+ User.objects.create(
+ email = email,
+ phone = phone,
+ full_name = full_name,
+ user_name = user_name,
+ password = hashed_password,
+ date_of_birth = date_of_birth,
+ )
+
+ return JsonResponse({'message':'SUCCESS'}, status=200)
+
+ except KeyError:
+ return JsonResponse({'message':'KEY ERROR'}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ user_id = data['user_id']
+ password = data['password']
+
+ user= User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id))
+
+ if user:
+ stored_password = User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id)).password
+ if not bcrypt.checkpw(password.encode('UTF-8'), stored_password.encode('UTF-8')):
+ return JsonResponse({"message":"INVALID_PASSWORD"}, status=401)
+ else:
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ return JsonResponse({"message":"SUCCESS", "Authorization":LoginCheck(user.id)}, status=200)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
\ No newline at end of file | Python | ๊น๋ํฉ๋๋ค!! ๐ฏ ๐ฏ ๐ฏ |
@@ -0,0 +1,87 @@
+import re, json, bcrypt
+
+from django.views import View
+from django.http import JsonResponse, request
+from django.db.models.query_utils import Q
+from json.decoder import JSONDecodeError
+
+from user.utils import LoginCheck
+from user.models import User
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ email = data['email']
+ password = data['password']
+ phone = data.get('phone', None)
+ full_name = data.get('full_name', None)
+ user_name = data.get('user_name', None)
+ date_of_birth = data.get('date_of_birth', None)
+
+ if phone:
+ phone = phone.replace('-','')
+
+ REGEX_EMAIL = '^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
+ REGEX_PASSWORD = '\S{8,20}'
+
+ if not re.match(REGEX_EMAIL,email):
+ return JsonResponse({'message':'EMAIL VALIDATION ERROR'}, status=400)
+ if not re.match(REGEX_PASSWORD,password):
+ return JsonResponse({'message':'PASSWORD VALIDATION ERROR'}, status=400)
+
+ if not User.objects.filter(email=email):
+ if phone and User.objects.filter(phone=phone):
+ return JsonResponse({'message':'PHONE ALREADY EXISTS'}, status=400)
+ elif user_name and User.objects.filter(user_name=user_name):
+ return JsonResponse({'message':'USER_NAME ALREADY EXISTS'}, status=400)
+ else:
+ return JsonResponse({'message':'EMAIL ALREADY EXISTS'}, status=400)
+
+ hashed_password = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt()).decode()
+
+ User.objects.create(
+ email = email,
+ phone = phone,
+ full_name = full_name,
+ user_name = user_name,
+ password = hashed_password,
+ date_of_birth = date_of_birth,
+ )
+
+ return JsonResponse({'message':'SUCCESS'}, status=200)
+
+ except KeyError:
+ return JsonResponse({'message':'KEY ERROR'}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ user_id = data['user_id']
+ password = data['password']
+
+ user= User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id))
+
+ if user:
+ stored_password = User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id)).password
+ if not bcrypt.checkpw(password.encode('UTF-8'), stored_password.encode('UTF-8')):
+ return JsonResponse({"message":"INVALID_PASSWORD"}, status=401)
+ else:
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ return JsonResponse({"message":"SUCCESS", "Authorization":LoginCheck(user.id)}, status=200)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
\ No newline at end of file | Python | ํ์ํ๋, `NULL` ํ์ฉํ๋์ ๋ฐ๋ฅธ ์ ๊ทผ ๋ฐฉ์ ๋ค๋ฅด๊ฒ ์ ์ฉ ์ํ์
จ์ต๋๋ค!! ๐๐๐
๊ฐ๋
์ฑ์ ์ํด ์กฐ๊ธ ์์น๋ฅผ ๋ณ๊ฒฝํ ์ ์๊ฒ ๋ค์! ์๋์ ๊ฐ์ด์ใ
ใ
```suggestion
email = data['email']
password = data['password']
phone = data.get('phone', None)
full_name = data.get('full_name', None)
user_name = data.get('user_name', None)
date_of_birth = data.get('date_of_birth', None)
``` |
@@ -0,0 +1,87 @@
+import re, json, bcrypt
+
+from django.views import View
+from django.http import JsonResponse, request
+from django.db.models.query_utils import Q
+from json.decoder import JSONDecodeError
+
+from user.utils import LoginCheck
+from user.models import User
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ email = data['email']
+ password = data['password']
+ phone = data.get('phone', None)
+ full_name = data.get('full_name', None)
+ user_name = data.get('user_name', None)
+ date_of_birth = data.get('date_of_birth', None)
+
+ if phone:
+ phone = phone.replace('-','')
+
+ REGEX_EMAIL = '^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
+ REGEX_PASSWORD = '\S{8,20}'
+
+ if not re.match(REGEX_EMAIL,email):
+ return JsonResponse({'message':'EMAIL VALIDATION ERROR'}, status=400)
+ if not re.match(REGEX_PASSWORD,password):
+ return JsonResponse({'message':'PASSWORD VALIDATION ERROR'}, status=400)
+
+ if not User.objects.filter(email=email):
+ if phone and User.objects.filter(phone=phone):
+ return JsonResponse({'message':'PHONE ALREADY EXISTS'}, status=400)
+ elif user_name and User.objects.filter(user_name=user_name):
+ return JsonResponse({'message':'USER_NAME ALREADY EXISTS'}, status=400)
+ else:
+ return JsonResponse({'message':'EMAIL ALREADY EXISTS'}, status=400)
+
+ hashed_password = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt()).decode()
+
+ User.objects.create(
+ email = email,
+ phone = phone,
+ full_name = full_name,
+ user_name = user_name,
+ password = hashed_password,
+ date_of_birth = date_of_birth,
+ )
+
+ return JsonResponse({'message':'SUCCESS'}, status=200)
+
+ except KeyError:
+ return JsonResponse({'message':'KEY ERROR'}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ user_id = data['user_id']
+ password = data['password']
+
+ user= User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id))
+
+ if user:
+ stored_password = User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id)).password
+ if not bcrypt.checkpw(password.encode('UTF-8'), stored_password.encode('UTF-8')):
+ return JsonResponse({"message":"INVALID_PASSWORD"}, status=401)
+ else:
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ return JsonResponse({"message":"SUCCESS", "Authorization":LoginCheck(user.id)}, status=200)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
\ No newline at end of file | Python | ์
๋ ฅ๋ฐ์ ํฐ๋ฒํธ์ `-` ๊ฐ ํฌํจ๋์ด ๋ค์ด์ฌ ์ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๋ฃ๊ณ ์ถ์ ํ์์ ๋ง์ถฐ์ฃผ์๋ ๋ก์ง ์ข์ต๋๋ค!
์์ผ๋ก ํ๋ก ํธ์๋๋ถ๋ค๊ณผ ํ์
์ ํ๋ฉด์ ๊ฒฝํํ์๊ฒ ์ง๋ง, ์ด๋ฐ ๋ถ๋ถ์ ๊ผญ ํ๋ก ํธ/๋ฐฑ ๊ฐ์ ์์๊ฐ ํ์ํฉ๋๋ค.
์ด ์ ์ธ์งํด์ฃผ์๊ณ ๋ค์ ์ฃผ ํ/๋ฐฑ ํต์ ๋ค์ด๊ฐ์๋ฉด ๋์์ด ๋์ค๊ฑฐ์์! ใ
ใ
|
@@ -0,0 +1,87 @@
+import re, json, bcrypt
+
+from django.views import View
+from django.http import JsonResponse, request
+from django.db.models.query_utils import Q
+from json.decoder import JSONDecodeError
+
+from user.utils import LoginCheck
+from user.models import User
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ email = data['email']
+ password = data['password']
+ phone = data.get('phone', None)
+ full_name = data.get('full_name', None)
+ user_name = data.get('user_name', None)
+ date_of_birth = data.get('date_of_birth', None)
+
+ if phone:
+ phone = phone.replace('-','')
+
+ REGEX_EMAIL = '^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
+ REGEX_PASSWORD = '\S{8,20}'
+
+ if not re.match(REGEX_EMAIL,email):
+ return JsonResponse({'message':'EMAIL VALIDATION ERROR'}, status=400)
+ if not re.match(REGEX_PASSWORD,password):
+ return JsonResponse({'message':'PASSWORD VALIDATION ERROR'}, status=400)
+
+ if not User.objects.filter(email=email):
+ if phone and User.objects.filter(phone=phone):
+ return JsonResponse({'message':'PHONE ALREADY EXISTS'}, status=400)
+ elif user_name and User.objects.filter(user_name=user_name):
+ return JsonResponse({'message':'USER_NAME ALREADY EXISTS'}, status=400)
+ else:
+ return JsonResponse({'message':'EMAIL ALREADY EXISTS'}, status=400)
+
+ hashed_password = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt()).decode()
+
+ User.objects.create(
+ email = email,
+ phone = phone,
+ full_name = full_name,
+ user_name = user_name,
+ password = hashed_password,
+ date_of_birth = date_of_birth,
+ )
+
+ return JsonResponse({'message':'SUCCESS'}, status=200)
+
+ except KeyError:
+ return JsonResponse({'message':'KEY ERROR'}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ user_id = data['user_id']
+ password = data['password']
+
+ user= User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id))
+
+ if user:
+ stored_password = User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id)).password
+ if not bcrypt.checkpw(password.encode('UTF-8'), stored_password.encode('UTF-8')):
+ return JsonResponse({"message":"INVALID_PASSWORD"}, status=401)
+ else:
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ return JsonResponse({"message":"SUCCESS", "Authorization":LoginCheck(user.id)}, status=200)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
\ No newline at end of file | Python | ์ ๊ทํํ์์ผ๋ก email ๊ณผ password validate ํด์ฃผ์๋ ๋ก์ง์ธ๋ฐ ์กฐ๊ธ ์์ํ๊ฒ ๋๋์ด์ ๋น๊ตํ์๋ ค๋ค๋ณด๋ ์กฐ๊ธ ๋ณต์กํด๋ณด์ด๋ค์!
์ฐจ๋ผ๋ฆฌ ์ด๋ฉ์ผ ํ์์ ๋ง๋ ์ ๊ทํํ์์ ํต์งธ๋ก ๊ฐ์ ธ์ ์ ์ฅํด๋๊ณ `re.match()` ๋ฅผ ํ์ฉํ์ฌ ํ๋ฒ์ ํ์ธํ ์ ์์ต๋๋ค. `password` ๋ ๋ง์ฐฌ๊ฐ์ง๊ตฌ์!
๊ทธ๋ ๊ฒ ๋ณ๊ฒฝํด์ฃผ์๋ฉด ์กฐ๊ธ ๋ ๊น๋ํ ์กฐ๊ฑด๋ฌธ์ ๋ง๋ค ์ ์์ต๋๋ค ๐ |
@@ -0,0 +1,87 @@
+import re, json, bcrypt
+
+from django.views import View
+from django.http import JsonResponse, request
+from django.db.models.query_utils import Q
+from json.decoder import JSONDecodeError
+
+from user.utils import LoginCheck
+from user.models import User
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ email = data['email']
+ password = data['password']
+ phone = data.get('phone', None)
+ full_name = data.get('full_name', None)
+ user_name = data.get('user_name', None)
+ date_of_birth = data.get('date_of_birth', None)
+
+ if phone:
+ phone = phone.replace('-','')
+
+ REGEX_EMAIL = '^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
+ REGEX_PASSWORD = '\S{8,20}'
+
+ if not re.match(REGEX_EMAIL,email):
+ return JsonResponse({'message':'EMAIL VALIDATION ERROR'}, status=400)
+ if not re.match(REGEX_PASSWORD,password):
+ return JsonResponse({'message':'PASSWORD VALIDATION ERROR'}, status=400)
+
+ if not User.objects.filter(email=email):
+ if phone and User.objects.filter(phone=phone):
+ return JsonResponse({'message':'PHONE ALREADY EXISTS'}, status=400)
+ elif user_name and User.objects.filter(user_name=user_name):
+ return JsonResponse({'message':'USER_NAME ALREADY EXISTS'}, status=400)
+ else:
+ return JsonResponse({'message':'EMAIL ALREADY EXISTS'}, status=400)
+
+ hashed_password = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt()).decode()
+
+ User.objects.create(
+ email = email,
+ phone = phone,
+ full_name = full_name,
+ user_name = user_name,
+ password = hashed_password,
+ date_of_birth = date_of_birth,
+ )
+
+ return JsonResponse({'message':'SUCCESS'}, status=200)
+
+ except KeyError:
+ return JsonResponse({'message':'KEY ERROR'}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ user_id = data['user_id']
+ password = data['password']
+
+ user= User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id))
+
+ if user:
+ stored_password = User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id)).password
+ if not bcrypt.checkpw(password.encode('UTF-8'), stored_password.encode('UTF-8')):
+ return JsonResponse({"message":"INVALID_PASSWORD"}, status=401)
+ else:
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ return JsonResponse({"message":"SUCCESS", "Authorization":LoginCheck(user.id)}, status=200)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
\ No newline at end of file | Python | ์ด๋ฏธ ์กด์ฌํ๋ ์ ๋ณด์ธ์ง ํ์ธํ๋ ๋ก์ง์ ์์ฑํด์ฃผ์
จ๋๋ฐ ์์ฑํด์ฃผ์ ๋ก์ง์ ํ๋ฆ๋๋ก ๊ธ๋ก ์ ๋ฆฌํด๋ณด๊ฒ ์ต๋๋ค.
1. ์
๋ ฅ๋ฐ์ `email` ๊ฐ์ผ๋ก ์ ์ ํ
์ด๋ธ์ filter ์ฟผ๋ฆฌ๋ฅผ ๋ ๋ ค ๋ฐํ๋ฐ์ QuerySet ๋ฆฌ์คํธ์ ๊ฐ์ฒด๊ฐ ์กด์ฌํ์ง ์๋๋ค๋ฉด `phone_number` ๊ณผ `user_name` ์ผ๋ก filter ์ฟผ๋ฆฌ๋ฅผ ๋ ๋ ค ์ถ๊ฐ ํ์ธ์ ํ๋ค.
2. ์กด์ฌํ๋ค๋ฉด `400` ์ ๋ฆฌํดํด์ค๋ค.
ํ์ง๋ง ํ์ฌ `SignUp` View ์์๋ `email` ์ ํ์๊ฐ์ผ๋ก ๋ฐ์์ผํ๊ธฐ ๋๋ฌธ์ ์ฌ์ค์ `email` ์กด์ฌ ์ ๋ฌด๋ง ํ์ธํด๋ ๋ฑ๋ก๋ ์ ์ ์ธ์ง ์๋์ง๋ ์ ์๊ฐ ์์ต๋๋ค. `phone_number` ์ `user_name` ์ ๋ถ๊ฐ์ ๋ณด๋ค์ด๋๊น์!
๊ทธ๋ฐ๋ฐ `email` ๋ก ์กด์ฌ์ ๋ฌด๋ ํ์ธํ๋๋ผ๋ `phone_number` ์ `user_name` ์ ์ค๋ณต ๊ฐ๋ฅ ์ฌ๋ถ์ ๋ฐ๋ผ ์ถ๊ฐ ๋ก์ง์ ๋ฌ๋ผ์ง ์ ์์ต๋๋ค. ์ ๊ฐ ๋ชจ๋ธ์ชฝ์ ๋จ๊ฒจ๋๋ฆฐ ๋ฆฌ๋ทฐ๋ฅผ ํ์ธํด๋ณด์ ํ ์๊ฐํ์ ๊ตฌ์กฐ์ ๋ฐ๋ผ ์์ ํด์ฃผ์ ๋ค์ ๋ค์ํ๋ฒ ์ด์ชฝ ๋ถ๋ถ์ ํ์ธํด๋ณด์ธ์! |
@@ -0,0 +1,87 @@
+import re, json, bcrypt
+
+from django.views import View
+from django.http import JsonResponse, request
+from django.db.models.query_utils import Q
+from json.decoder import JSONDecodeError
+
+from user.utils import LoginCheck
+from user.models import User
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ email = data['email']
+ password = data['password']
+ phone = data.get('phone', None)
+ full_name = data.get('full_name', None)
+ user_name = data.get('user_name', None)
+ date_of_birth = data.get('date_of_birth', None)
+
+ if phone:
+ phone = phone.replace('-','')
+
+ REGEX_EMAIL = '^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
+ REGEX_PASSWORD = '\S{8,20}'
+
+ if not re.match(REGEX_EMAIL,email):
+ return JsonResponse({'message':'EMAIL VALIDATION ERROR'}, status=400)
+ if not re.match(REGEX_PASSWORD,password):
+ return JsonResponse({'message':'PASSWORD VALIDATION ERROR'}, status=400)
+
+ if not User.objects.filter(email=email):
+ if phone and User.objects.filter(phone=phone):
+ return JsonResponse({'message':'PHONE ALREADY EXISTS'}, status=400)
+ elif user_name and User.objects.filter(user_name=user_name):
+ return JsonResponse({'message':'USER_NAME ALREADY EXISTS'}, status=400)
+ else:
+ return JsonResponse({'message':'EMAIL ALREADY EXISTS'}, status=400)
+
+ hashed_password = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt()).decode()
+
+ User.objects.create(
+ email = email,
+ phone = phone,
+ full_name = full_name,
+ user_name = user_name,
+ password = hashed_password,
+ date_of_birth = date_of_birth,
+ )
+
+ return JsonResponse({'message':'SUCCESS'}, status=200)
+
+ except KeyError:
+ return JsonResponse({'message':'KEY ERROR'}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ user_id = data['user_id']
+ password = data['password']
+
+ user= User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id))
+
+ if user:
+ stored_password = User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id)).password
+ if not bcrypt.checkpw(password.encode('UTF-8'), stored_password.encode('UTF-8')):
+ return JsonResponse({"message":"INVALID_PASSWORD"}, status=401)
+ else:
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ return JsonResponse({"message":"SUCCESS", "Authorization":LoginCheck(user.id)}, status=200)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
\ No newline at end of file | Python | ๊น๋ํฉ๋๋ค~ ๐ฏ |
@@ -0,0 +1,87 @@
+import re, json, bcrypt
+
+from django.views import View
+from django.http import JsonResponse, request
+from django.db.models.query_utils import Q
+from json.decoder import JSONDecodeError
+
+from user.utils import LoginCheck
+from user.models import User
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ email = data['email']
+ password = data['password']
+ phone = data.get('phone', None)
+ full_name = data.get('full_name', None)
+ user_name = data.get('user_name', None)
+ date_of_birth = data.get('date_of_birth', None)
+
+ if phone:
+ phone = phone.replace('-','')
+
+ REGEX_EMAIL = '^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
+ REGEX_PASSWORD = '\S{8,20}'
+
+ if not re.match(REGEX_EMAIL,email):
+ return JsonResponse({'message':'EMAIL VALIDATION ERROR'}, status=400)
+ if not re.match(REGEX_PASSWORD,password):
+ return JsonResponse({'message':'PASSWORD VALIDATION ERROR'}, status=400)
+
+ if not User.objects.filter(email=email):
+ if phone and User.objects.filter(phone=phone):
+ return JsonResponse({'message':'PHONE ALREADY EXISTS'}, status=400)
+ elif user_name and User.objects.filter(user_name=user_name):
+ return JsonResponse({'message':'USER_NAME ALREADY EXISTS'}, status=400)
+ else:
+ return JsonResponse({'message':'EMAIL ALREADY EXISTS'}, status=400)
+
+ hashed_password = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt()).decode()
+
+ User.objects.create(
+ email = email,
+ phone = phone,
+ full_name = full_name,
+ user_name = user_name,
+ password = hashed_password,
+ date_of_birth = date_of_birth,
+ )
+
+ return JsonResponse({'message':'SUCCESS'}, status=200)
+
+ except KeyError:
+ return JsonResponse({'message':'KEY ERROR'}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ user_id = data['user_id']
+ password = data['password']
+
+ user= User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id))
+
+ if user:
+ stored_password = User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id)).password
+ if not bcrypt.checkpw(password.encode('UTF-8'), stored_password.encode('UTF-8')):
+ return JsonResponse({"message":"INVALID_PASSWORD"}, status=401)
+ else:
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ return JsonResponse({"message":"SUCCESS", "Authorization":LoginCheck(user.id)}, status=200)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
\ No newline at end of file | Python | ๊ตฌ๋ถ์ ์ํด ์์๋๋ก ํ์ค์ฉ ์ถ๊ฐํด์ฃผ์๋ฉด ๊ฐ๋
์ฑ์ด ๋ ์ข์์ง๊ฒ ๋ค์! ๐ |
@@ -0,0 +1,87 @@
+import re, json, bcrypt
+
+from django.views import View
+from django.http import JsonResponse, request
+from django.db.models.query_utils import Q
+from json.decoder import JSONDecodeError
+
+from user.utils import LoginCheck
+from user.models import User
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ email = data['email']
+ password = data['password']
+ phone = data.get('phone', None)
+ full_name = data.get('full_name', None)
+ user_name = data.get('user_name', None)
+ date_of_birth = data.get('date_of_birth', None)
+
+ if phone:
+ phone = phone.replace('-','')
+
+ REGEX_EMAIL = '^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
+ REGEX_PASSWORD = '\S{8,20}'
+
+ if not re.match(REGEX_EMAIL,email):
+ return JsonResponse({'message':'EMAIL VALIDATION ERROR'}, status=400)
+ if not re.match(REGEX_PASSWORD,password):
+ return JsonResponse({'message':'PASSWORD VALIDATION ERROR'}, status=400)
+
+ if not User.objects.filter(email=email):
+ if phone and User.objects.filter(phone=phone):
+ return JsonResponse({'message':'PHONE ALREADY EXISTS'}, status=400)
+ elif user_name and User.objects.filter(user_name=user_name):
+ return JsonResponse({'message':'USER_NAME ALREADY EXISTS'}, status=400)
+ else:
+ return JsonResponse({'message':'EMAIL ALREADY EXISTS'}, status=400)
+
+ hashed_password = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt()).decode()
+
+ User.objects.create(
+ email = email,
+ phone = phone,
+ full_name = full_name,
+ user_name = user_name,
+ password = hashed_password,
+ date_of_birth = date_of_birth,
+ )
+
+ return JsonResponse({'message':'SUCCESS'}, status=200)
+
+ except KeyError:
+ return JsonResponse({'message':'KEY ERROR'}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ user_id = data['user_id']
+ password = data['password']
+
+ user= User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id))
+
+ if user:
+ stored_password = User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id)).password
+ if not bcrypt.checkpw(password.encode('UTF-8'), stored_password.encode('UTF-8')):
+ return JsonResponse({"message":"INVALID_PASSWORD"}, status=401)
+ else:
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ return JsonResponse({"message":"SUCCESS", "Authorization":LoginCheck(user.id)}, status=200)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
\ No newline at end of file | Python | ์ด๋ฐ์์ผ๋ก exception ์ ์ฒ๋ฆฌํ์๊ฒ ๋๋ฉด ์ด๋ค exception ์ด ๋ฌด์๋๋ฌธ์ `raise` ๋์๋์ง ํ์ธํ๊ธฐ๊ฐ ์ด๋ ต์ต๋๋ค. ๊ทธ๋์ exception ํธ๋ค๋ฌ ์ถ๊ฐํด์ฃผ์ค๋๋ ์์์ `KeyError` ์ฒ๋ฆฌํด์ฃผ์ ๊ฒ๊ณผ ๊ฐ์ด ๋ช
ํํ๊ฒ ์ง์ ํ์ฌ ์ฒ๋ฆฌํด์ฃผ์
์ผํฉ๋๋ค.
ํ์ง๋ง ์ง๊ธ ๋จ๊ณ์์ ์ด๋ค exception ์ด ๋ฐ์ํ ์ ์๋์ง ๋ชจ๋ฅด๋๊ฒ ๋น์ฐํ๊ธฐ ๋๋ฌธ์ ์ด๋ด๋๋ ๊ทธ๋ฅ ์ฌ๋ฌ๊ฐ์ง ๋ฐฉ๋ฒ์ผ๋ก ํธ์ถํด๋ณด๋ฉด์ ๊ฒฝํํ์ฌ ์ถ๊ฐํด์ฃผ์๋ค๋ณด๋ฉด ๋์ค์๋ ๋ฉ์๋ ํ๋๋ฅผ ์ถ๊ฐํ ๋ ๊ด๋ จํ exception ์ ์ฒ๋ฆฌํด์ฃผ๋ ๋ก์ง์ ๋ฐ๋ก ํจ๊ป ์์ฑํ ์ ์๊ฒ ๋์ค๊ฑฐ์์! ๐ |
@@ -0,0 +1,12 @@
+from django.db import models
+
+class User(models.Model):
+ email = models.EmailField(max_length=50, unique=True)
+ phone = models.CharField(max_length=11, null=True, unique=True)
+ full_name = models.CharField(max_length=40, null=True)
+ user_name = models.CharField(max_length=20, null=True, unique=True)
+ password = models.CharField(max_length=70)
+ date_of_birth = models.DateField(null=True)
+
+ class Meta:
+ db_table = 'users' | Python | ๋ค๋ต!! |
@@ -0,0 +1,87 @@
+import re, json, bcrypt
+
+from django.views import View
+from django.http import JsonResponse, request
+from django.db.models.query_utils import Q
+from json.decoder import JSONDecodeError
+
+from user.utils import LoginCheck
+from user.models import User
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ email = data['email']
+ password = data['password']
+ phone = data.get('phone', None)
+ full_name = data.get('full_name', None)
+ user_name = data.get('user_name', None)
+ date_of_birth = data.get('date_of_birth', None)
+
+ if phone:
+ phone = phone.replace('-','')
+
+ REGEX_EMAIL = '^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
+ REGEX_PASSWORD = '\S{8,20}'
+
+ if not re.match(REGEX_EMAIL,email):
+ return JsonResponse({'message':'EMAIL VALIDATION ERROR'}, status=400)
+ if not re.match(REGEX_PASSWORD,password):
+ return JsonResponse({'message':'PASSWORD VALIDATION ERROR'}, status=400)
+
+ if not User.objects.filter(email=email):
+ if phone and User.objects.filter(phone=phone):
+ return JsonResponse({'message':'PHONE ALREADY EXISTS'}, status=400)
+ elif user_name and User.objects.filter(user_name=user_name):
+ return JsonResponse({'message':'USER_NAME ALREADY EXISTS'}, status=400)
+ else:
+ return JsonResponse({'message':'EMAIL ALREADY EXISTS'}, status=400)
+
+ hashed_password = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt()).decode()
+
+ User.objects.create(
+ email = email,
+ phone = phone,
+ full_name = full_name,
+ user_name = user_name,
+ password = hashed_password,
+ date_of_birth = date_of_birth,
+ )
+
+ return JsonResponse({'message':'SUCCESS'}, status=200)
+
+ except KeyError:
+ return JsonResponse({'message':'KEY ERROR'}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ user_id = data['user_id']
+ password = data['password']
+
+ user= User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id))
+
+ if user:
+ stored_password = User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id)).password
+ if not bcrypt.checkpw(password.encode('UTF-8'), stored_password.encode('UTF-8')):
+ return JsonResponse({"message":"INVALID_PASSWORD"}, status=401)
+ else:
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ return JsonResponse({"message":"SUCCESS", "Authorization":LoginCheck(user.id)}, status=200)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
\ No newline at end of file | Python | ์ํ ๋ค๋ต!! ๊ถ๊ธํ ์ ํด๊ฒฐ ๋์์ต๋๋ค ใ
ใ
!! |
@@ -0,0 +1,87 @@
+import re, json, bcrypt
+
+from django.views import View
+from django.http import JsonResponse, request
+from django.db.models.query_utils import Q
+from json.decoder import JSONDecodeError
+
+from user.utils import LoginCheck
+from user.models import User
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ email = data['email']
+ password = data['password']
+ phone = data.get('phone', None)
+ full_name = data.get('full_name', None)
+ user_name = data.get('user_name', None)
+ date_of_birth = data.get('date_of_birth', None)
+
+ if phone:
+ phone = phone.replace('-','')
+
+ REGEX_EMAIL = '^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
+ REGEX_PASSWORD = '\S{8,20}'
+
+ if not re.match(REGEX_EMAIL,email):
+ return JsonResponse({'message':'EMAIL VALIDATION ERROR'}, status=400)
+ if not re.match(REGEX_PASSWORD,password):
+ return JsonResponse({'message':'PASSWORD VALIDATION ERROR'}, status=400)
+
+ if not User.objects.filter(email=email):
+ if phone and User.objects.filter(phone=phone):
+ return JsonResponse({'message':'PHONE ALREADY EXISTS'}, status=400)
+ elif user_name and User.objects.filter(user_name=user_name):
+ return JsonResponse({'message':'USER_NAME ALREADY EXISTS'}, status=400)
+ else:
+ return JsonResponse({'message':'EMAIL ALREADY EXISTS'}, status=400)
+
+ hashed_password = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt()).decode()
+
+ User.objects.create(
+ email = email,
+ phone = phone,
+ full_name = full_name,
+ user_name = user_name,
+ password = hashed_password,
+ date_of_birth = date_of_birth,
+ )
+
+ return JsonResponse({'message':'SUCCESS'}, status=200)
+
+ except KeyError:
+ return JsonResponse({'message':'KEY ERROR'}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ user_id = data['user_id']
+ password = data['password']
+
+ user= User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id))
+
+ if user:
+ stored_password = User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id)).password
+ if not bcrypt.checkpw(password.encode('UTF-8'), stored_password.encode('UTF-8')):
+ return JsonResponse({"message":"INVALID_PASSWORD"}, status=401)
+ else:
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ return JsonResponse({"message":"SUCCESS", "Authorization":LoginCheck(user.id)}, status=200)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
\ No newline at end of file | Python | ์นํ๋, ๋ง์ํ์ ๋๋ก, ์ด๋ฉ์ผ ์ฃผ์์ ๋น๋ฐ๋ฒํธ ์ ๊ท์ ๊ฒ์ฌ์ ํ์ํ ๊ฐ์ REGEX_EMAIL, REGEX_PASSWORD์๋ค๊ฐ ์ ์ฅํ์ฌ ํ์ฉํ์์ต๋๋ค..! ๋ณด๋ค ์ฝ๋๊ฐ ๊ฐ๊ฒฐํด์ ธ์ ์์ฃผ ์ข๋ค์ ใ
ใ
ใ
|
@@ -0,0 +1,87 @@
+import re, json, bcrypt
+
+from django.views import View
+from django.http import JsonResponse, request
+from django.db.models.query_utils import Q
+from json.decoder import JSONDecodeError
+
+from user.utils import LoginCheck
+from user.models import User
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ email = data['email']
+ password = data['password']
+ phone = data.get('phone', None)
+ full_name = data.get('full_name', None)
+ user_name = data.get('user_name', None)
+ date_of_birth = data.get('date_of_birth', None)
+
+ if phone:
+ phone = phone.replace('-','')
+
+ REGEX_EMAIL = '^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
+ REGEX_PASSWORD = '\S{8,20}'
+
+ if not re.match(REGEX_EMAIL,email):
+ return JsonResponse({'message':'EMAIL VALIDATION ERROR'}, status=400)
+ if not re.match(REGEX_PASSWORD,password):
+ return JsonResponse({'message':'PASSWORD VALIDATION ERROR'}, status=400)
+
+ if not User.objects.filter(email=email):
+ if phone and User.objects.filter(phone=phone):
+ return JsonResponse({'message':'PHONE ALREADY EXISTS'}, status=400)
+ elif user_name and User.objects.filter(user_name=user_name):
+ return JsonResponse({'message':'USER_NAME ALREADY EXISTS'}, status=400)
+ else:
+ return JsonResponse({'message':'EMAIL ALREADY EXISTS'}, status=400)
+
+ hashed_password = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt()).decode()
+
+ User.objects.create(
+ email = email,
+ phone = phone,
+ full_name = full_name,
+ user_name = user_name,
+ password = hashed_password,
+ date_of_birth = date_of_birth,
+ )
+
+ return JsonResponse({'message':'SUCCESS'}, status=200)
+
+ except KeyError:
+ return JsonResponse({'message':'KEY ERROR'}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ user_id = data['user_id']
+ password = data['password']
+
+ user= User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id))
+
+ if user:
+ stored_password = User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id)).password
+ if not bcrypt.checkpw(password.encode('UTF-8'), stored_password.encode('UTF-8')):
+ return JsonResponse({"message":"INVALID_PASSWORD"}, status=401)
+ else:
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ return JsonResponse({"message":"SUCCESS", "Authorization":LoginCheck(user.id)}, status=200)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
\ No newline at end of file | Python | ์นํ๋, ์๊น ํด์ฃผ์ ๋ง์ ๋ฃ๊ณ User ํด๋์ค์ ํน์ ์ปฌ๋ผ์ ๊ณ ์ ํ ๊ฐ์ ๊ฐ์ง๋๋ก unique ์ต์
์ ์ค์ ํ์์ต๋๋ค..! ๊ทธ๋ฆฌ๊ณ ๋ง์ํด์ฃผ์ q ํด๋์ค๋ ๊ณต๋ถํ๊ณ ๋ค์ ์์ค์๋ ์ ์ฉํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค!! |
@@ -0,0 +1,87 @@
+import re, json, bcrypt
+
+from django.views import View
+from django.http import JsonResponse, request
+from django.db.models.query_utils import Q
+from json.decoder import JSONDecodeError
+
+from user.utils import LoginCheck
+from user.models import User
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ email = data['email']
+ password = data['password']
+ phone = data.get('phone', None)
+ full_name = data.get('full_name', None)
+ user_name = data.get('user_name', None)
+ date_of_birth = data.get('date_of_birth', None)
+
+ if phone:
+ phone = phone.replace('-','')
+
+ REGEX_EMAIL = '^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
+ REGEX_PASSWORD = '\S{8,20}'
+
+ if not re.match(REGEX_EMAIL,email):
+ return JsonResponse({'message':'EMAIL VALIDATION ERROR'}, status=400)
+ if not re.match(REGEX_PASSWORD,password):
+ return JsonResponse({'message':'PASSWORD VALIDATION ERROR'}, status=400)
+
+ if not User.objects.filter(email=email):
+ if phone and User.objects.filter(phone=phone):
+ return JsonResponse({'message':'PHONE ALREADY EXISTS'}, status=400)
+ elif user_name and User.objects.filter(user_name=user_name):
+ return JsonResponse({'message':'USER_NAME ALREADY EXISTS'}, status=400)
+ else:
+ return JsonResponse({'message':'EMAIL ALREADY EXISTS'}, status=400)
+
+ hashed_password = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt()).decode()
+
+ User.objects.create(
+ email = email,
+ phone = phone,
+ full_name = full_name,
+ user_name = user_name,
+ password = hashed_password,
+ date_of_birth = date_of_birth,
+ )
+
+ return JsonResponse({'message':'SUCCESS'}, status=200)
+
+ except KeyError:
+ return JsonResponse({'message':'KEY ERROR'}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ user_id = data['user_id']
+ password = data['password']
+
+ user= User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id))
+
+ if user:
+ stored_password = User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id)).password
+ if not bcrypt.checkpw(password.encode('UTF-8'), stored_password.encode('UTF-8')):
+ return JsonResponse({"message":"INVALID_PASSWORD"}, status=401)
+ else:
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ return JsonResponse({"message":"SUCCESS", "Authorization":LoginCheck(user.id)}, status=200)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
\ No newline at end of file | Python | Truthy, Falsy values ์ ๋ํด ์์๋ณด์๊ณ ํด๋น ์กฐ๊ฑด๋ฌธ๋ค์ ์ด๋ป๊ฒ ๋ ๊น๋ํ๊ฒ ์ ๋ฆฌํ ์ ์์์ง ๊ณ ๋ฏผํด๋ณด์๊ณ ์ ์ฉํด์ฃผ์ธ์! |
@@ -0,0 +1,87 @@
+import re, json, bcrypt
+
+from django.views import View
+from django.http import JsonResponse, request
+from django.db.models.query_utils import Q
+from json.decoder import JSONDecodeError
+
+from user.utils import LoginCheck
+from user.models import User
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ email = data['email']
+ password = data['password']
+ phone = data.get('phone', None)
+ full_name = data.get('full_name', None)
+ user_name = data.get('user_name', None)
+ date_of_birth = data.get('date_of_birth', None)
+
+ if phone:
+ phone = phone.replace('-','')
+
+ REGEX_EMAIL = '^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
+ REGEX_PASSWORD = '\S{8,20}'
+
+ if not re.match(REGEX_EMAIL,email):
+ return JsonResponse({'message':'EMAIL VALIDATION ERROR'}, status=400)
+ if not re.match(REGEX_PASSWORD,password):
+ return JsonResponse({'message':'PASSWORD VALIDATION ERROR'}, status=400)
+
+ if not User.objects.filter(email=email):
+ if phone and User.objects.filter(phone=phone):
+ return JsonResponse({'message':'PHONE ALREADY EXISTS'}, status=400)
+ elif user_name and User.objects.filter(user_name=user_name):
+ return JsonResponse({'message':'USER_NAME ALREADY EXISTS'}, status=400)
+ else:
+ return JsonResponse({'message':'EMAIL ALREADY EXISTS'}, status=400)
+
+ hashed_password = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt()).decode()
+
+ User.objects.create(
+ email = email,
+ phone = phone,
+ full_name = full_name,
+ user_name = user_name,
+ password = hashed_password,
+ date_of_birth = date_of_birth,
+ )
+
+ return JsonResponse({'message':'SUCCESS'}, status=200)
+
+ except KeyError:
+ return JsonResponse({'message':'KEY ERROR'}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ user_id = data['user_id']
+ password = data['password']
+
+ user= User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id))
+
+ if user:
+ stored_password = User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id)).password
+ if not bcrypt.checkpw(password.encode('UTF-8'), stored_password.encode('UTF-8')):
+ return JsonResponse({"message":"INVALID_PASSWORD"}, status=401)
+ else:
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ return JsonResponse({"message":"SUCCESS", "Authorization":LoginCheck(user.id)}, status=200)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
\ No newline at end of file | Python | ์ด์ bcrypt ๋ก ๋น๋ฐ๋ฒํธ๋ฅผ ์ํธํํ์ฌ ์ ์ฅํ๋ ๋ก์ง์ ์ถ๊ฐํด์ฃผ์ธ์! |
@@ -0,0 +1,87 @@
+import re, json, bcrypt
+
+from django.views import View
+from django.http import JsonResponse, request
+from django.db.models.query_utils import Q
+from json.decoder import JSONDecodeError
+
+from user.utils import LoginCheck
+from user.models import User
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ email = data['email']
+ password = data['password']
+ phone = data.get('phone', None)
+ full_name = data.get('full_name', None)
+ user_name = data.get('user_name', None)
+ date_of_birth = data.get('date_of_birth', None)
+
+ if phone:
+ phone = phone.replace('-','')
+
+ REGEX_EMAIL = '^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
+ REGEX_PASSWORD = '\S{8,20}'
+
+ if not re.match(REGEX_EMAIL,email):
+ return JsonResponse({'message':'EMAIL VALIDATION ERROR'}, status=400)
+ if not re.match(REGEX_PASSWORD,password):
+ return JsonResponse({'message':'PASSWORD VALIDATION ERROR'}, status=400)
+
+ if not User.objects.filter(email=email):
+ if phone and User.objects.filter(phone=phone):
+ return JsonResponse({'message':'PHONE ALREADY EXISTS'}, status=400)
+ elif user_name and User.objects.filter(user_name=user_name):
+ return JsonResponse({'message':'USER_NAME ALREADY EXISTS'}, status=400)
+ else:
+ return JsonResponse({'message':'EMAIL ALREADY EXISTS'}, status=400)
+
+ hashed_password = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt()).decode()
+
+ User.objects.create(
+ email = email,
+ phone = phone,
+ full_name = full_name,
+ user_name = user_name,
+ password = hashed_password,
+ date_of_birth = date_of_birth,
+ )
+
+ return JsonResponse({'message':'SUCCESS'}, status=200)
+
+ except KeyError:
+ return JsonResponse({'message':'KEY ERROR'}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ user_id = data['user_id']
+ password = data['password']
+
+ user= User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id))
+
+ if user:
+ stored_password = User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id)).password
+ if not bcrypt.checkpw(password.encode('UTF-8'), stored_password.encode('UTF-8')):
+ return JsonResponse({"message":"INVALID_PASSWORD"}, status=401)
+ else:
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ return JsonResponse({"message":"SUCCESS", "Authorization":LoginCheck(user.id)}, status=200)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
\ No newline at end of file | Python | ์ฌ๊ธฐ์๋ ๋ฐ์ํ ์ ์๋ exception ์ด ์กด์ฌํฉ๋๋ค!
exception handling ๋ก์ง์ ์ถ๊ฐํด์ฃผ์ธ์!! |
@@ -0,0 +1,87 @@
+import re, json, bcrypt
+
+from django.views import View
+from django.http import JsonResponse, request
+from django.db.models.query_utils import Q
+from json.decoder import JSONDecodeError
+
+from user.utils import LoginCheck
+from user.models import User
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ email = data['email']
+ password = data['password']
+ phone = data.get('phone', None)
+ full_name = data.get('full_name', None)
+ user_name = data.get('user_name', None)
+ date_of_birth = data.get('date_of_birth', None)
+
+ if phone:
+ phone = phone.replace('-','')
+
+ REGEX_EMAIL = '^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
+ REGEX_PASSWORD = '\S{8,20}'
+
+ if not re.match(REGEX_EMAIL,email):
+ return JsonResponse({'message':'EMAIL VALIDATION ERROR'}, status=400)
+ if not re.match(REGEX_PASSWORD,password):
+ return JsonResponse({'message':'PASSWORD VALIDATION ERROR'}, status=400)
+
+ if not User.objects.filter(email=email):
+ if phone and User.objects.filter(phone=phone):
+ return JsonResponse({'message':'PHONE ALREADY EXISTS'}, status=400)
+ elif user_name and User.objects.filter(user_name=user_name):
+ return JsonResponse({'message':'USER_NAME ALREADY EXISTS'}, status=400)
+ else:
+ return JsonResponse({'message':'EMAIL ALREADY EXISTS'}, status=400)
+
+ hashed_password = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt()).decode()
+
+ User.objects.create(
+ email = email,
+ phone = phone,
+ full_name = full_name,
+ user_name = user_name,
+ password = hashed_password,
+ date_of_birth = date_of_birth,
+ )
+
+ return JsonResponse({'message':'SUCCESS'}, status=200)
+
+ except KeyError:
+ return JsonResponse({'message':'KEY ERROR'}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ user_id = data['user_id']
+ password = data['password']
+
+ user= User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id))
+
+ if user:
+ stored_password = User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id)).password
+ if not bcrypt.checkpw(password.encode('UTF-8'), stored_password.encode('UTF-8')):
+ return JsonResponse({"message":"INVALID_PASSWORD"}, status=401)
+ else:
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ return JsonResponse({"message":"SUCCESS", "Authorization":LoginCheck(user.id)}, status=200)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
\ No newline at end of file | Python | `=` ๊ธฐ์ค ๊ฐ๊ฒฉ ์ ๋ ฌํด์ฃผ์ธ์ ๊ตญํ๋! |
@@ -0,0 +1,87 @@
+import re, json, bcrypt
+
+from django.views import View
+from django.http import JsonResponse, request
+from django.db.models.query_utils import Q
+from json.decoder import JSONDecodeError
+
+from user.utils import LoginCheck
+from user.models import User
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ email = data['email']
+ password = data['password']
+ phone = data.get('phone', None)
+ full_name = data.get('full_name', None)
+ user_name = data.get('user_name', None)
+ date_of_birth = data.get('date_of_birth', None)
+
+ if phone:
+ phone = phone.replace('-','')
+
+ REGEX_EMAIL = '^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
+ REGEX_PASSWORD = '\S{8,20}'
+
+ if not re.match(REGEX_EMAIL,email):
+ return JsonResponse({'message':'EMAIL VALIDATION ERROR'}, status=400)
+ if not re.match(REGEX_PASSWORD,password):
+ return JsonResponse({'message':'PASSWORD VALIDATION ERROR'}, status=400)
+
+ if not User.objects.filter(email=email):
+ if phone and User.objects.filter(phone=phone):
+ return JsonResponse({'message':'PHONE ALREADY EXISTS'}, status=400)
+ elif user_name and User.objects.filter(user_name=user_name):
+ return JsonResponse({'message':'USER_NAME ALREADY EXISTS'}, status=400)
+ else:
+ return JsonResponse({'message':'EMAIL ALREADY EXISTS'}, status=400)
+
+ hashed_password = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt()).decode()
+
+ User.objects.create(
+ email = email,
+ phone = phone,
+ full_name = full_name,
+ user_name = user_name,
+ password = hashed_password,
+ date_of_birth = date_of_birth,
+ )
+
+ return JsonResponse({'message':'SUCCESS'}, status=200)
+
+ except KeyError:
+ return JsonResponse({'message':'KEY ERROR'}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ user_id = data['user_id']
+ password = data['password']
+
+ user= User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id))
+
+ if user:
+ stored_password = User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id)).password
+ if not bcrypt.checkpw(password.encode('UTF-8'), stored_password.encode('UTF-8')):
+ return JsonResponse({"message":"INVALID_PASSWORD"}, status=401)
+ else:
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ return JsonResponse({"message":"SUCCESS", "Authorization":LoginCheck(user.id)}, status=200)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
\ No newline at end of file | Python | - `|` ์ฌ์ด ๊ฐ๊ฒฉ๋ ํต์ผํด์ฃผ์ธ์~
- ์ด ๋ถ๋ถ ๋ก์ง์ด ์ดํด๊ฐ ์ ์๋๋๋ฐ ์ ๋ถ user_id ๋ฅผ ๋์
ํ์ฌ ํ์ธํ๊ณ ์ถ์๊ฒ ๋ง์ผ์ ๊ฐ์?! |
@@ -0,0 +1,87 @@
+import re, json, bcrypt
+
+from django.views import View
+from django.http import JsonResponse, request
+from django.db.models.query_utils import Q
+from json.decoder import JSONDecodeError
+
+from user.utils import LoginCheck
+from user.models import User
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ email = data['email']
+ password = data['password']
+ phone = data.get('phone', None)
+ full_name = data.get('full_name', None)
+ user_name = data.get('user_name', None)
+ date_of_birth = data.get('date_of_birth', None)
+
+ if phone:
+ phone = phone.replace('-','')
+
+ REGEX_EMAIL = '^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
+ REGEX_PASSWORD = '\S{8,20}'
+
+ if not re.match(REGEX_EMAIL,email):
+ return JsonResponse({'message':'EMAIL VALIDATION ERROR'}, status=400)
+ if not re.match(REGEX_PASSWORD,password):
+ return JsonResponse({'message':'PASSWORD VALIDATION ERROR'}, status=400)
+
+ if not User.objects.filter(email=email):
+ if phone and User.objects.filter(phone=phone):
+ return JsonResponse({'message':'PHONE ALREADY EXISTS'}, status=400)
+ elif user_name and User.objects.filter(user_name=user_name):
+ return JsonResponse({'message':'USER_NAME ALREADY EXISTS'}, status=400)
+ else:
+ return JsonResponse({'message':'EMAIL ALREADY EXISTS'}, status=400)
+
+ hashed_password = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt()).decode()
+
+ User.objects.create(
+ email = email,
+ phone = phone,
+ full_name = full_name,
+ user_name = user_name,
+ password = hashed_password,
+ date_of_birth = date_of_birth,
+ )
+
+ return JsonResponse({'message':'SUCCESS'}, status=200)
+
+ except KeyError:
+ return JsonResponse({'message':'KEY ERROR'}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ user_id = data['user_id']
+ password = data['password']
+
+ user= User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id))
+
+ if user:
+ stored_password = User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id)).password
+ if not bcrypt.checkpw(password.encode('UTF-8'), stored_password.encode('UTF-8')):
+ return JsonResponse({"message":"INVALID_PASSWORD"}, status=401)
+ else:
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ return JsonResponse({"message":"SUCCESS", "Authorization":LoginCheck(user.id)}, status=200)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
\ No newline at end of file | Python | ๋ต๋ต!! ์์ ํด๋ณด๊ฒ ์ต๋๋ค~~ |
@@ -0,0 +1,87 @@
+import re, json, bcrypt
+
+from django.views import View
+from django.http import JsonResponse, request
+from django.db.models.query_utils import Q
+from json.decoder import JSONDecodeError
+
+from user.utils import LoginCheck
+from user.models import User
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ email = data['email']
+ password = data['password']
+ phone = data.get('phone', None)
+ full_name = data.get('full_name', None)
+ user_name = data.get('user_name', None)
+ date_of_birth = data.get('date_of_birth', None)
+
+ if phone:
+ phone = phone.replace('-','')
+
+ REGEX_EMAIL = '^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
+ REGEX_PASSWORD = '\S{8,20}'
+
+ if not re.match(REGEX_EMAIL,email):
+ return JsonResponse({'message':'EMAIL VALIDATION ERROR'}, status=400)
+ if not re.match(REGEX_PASSWORD,password):
+ return JsonResponse({'message':'PASSWORD VALIDATION ERROR'}, status=400)
+
+ if not User.objects.filter(email=email):
+ if phone and User.objects.filter(phone=phone):
+ return JsonResponse({'message':'PHONE ALREADY EXISTS'}, status=400)
+ elif user_name and User.objects.filter(user_name=user_name):
+ return JsonResponse({'message':'USER_NAME ALREADY EXISTS'}, status=400)
+ else:
+ return JsonResponse({'message':'EMAIL ALREADY EXISTS'}, status=400)
+
+ hashed_password = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt()).decode()
+
+ User.objects.create(
+ email = email,
+ phone = phone,
+ full_name = full_name,
+ user_name = user_name,
+ password = hashed_password,
+ date_of_birth = date_of_birth,
+ )
+
+ return JsonResponse({'message':'SUCCESS'}, status=200)
+
+ except KeyError:
+ return JsonResponse({'message':'KEY ERROR'}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ user_id = data['user_id']
+ password = data['password']
+
+ user= User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id))
+
+ if user:
+ stored_password = User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id)).password
+ if not bcrypt.checkpw(password.encode('UTF-8'), stored_password.encode('UTF-8')):
+ return JsonResponse({"message":"INVALID_PASSWORD"}, status=401)
+ else:
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ return JsonResponse({"message":"SUCCESS", "Authorization":LoginCheck(user.id)}, status=200)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
\ No newline at end of file | Python | ๋ต ์นํ๋!
์ ๋ ์ฌ์ฉ์๊ฐ ๋ก๊ทธ์ธํ ๋ ์ด๋ฉ์ผ, ํด๋ํฐ, ์ ์ ๋ค์ ์ด ์ธ๊ฐ์ค์ ํ๋๋ก ๋ก๊ทธ์ธํ ๊บผ๋ผ๊ณ ์๊ฐ์ ํด์ ์ฌ์ฉ์๊ฐ ์
๋ ฅํ ๊ฐ์ ์์ user_id๋ก ๊ฐ์ ๋ฐ์ผ๋ ค ํ์ต๋๋ค..! ๊ทธ๋์ ์ด user_id๊ฐ์ ๊ฐ์ง๊ณ ํ๋๋ผ๋ ์ด๋ฉ์ผ, ํด๋ํฐ, ์ ์ ๋ค์๊ณผ ๊ฐ์๊ฒ ์์ผ๋ฉด ์ ํจํ ์์ด๋๊ฐ์ด๋ผ๊ณ ์๊ฐํ์์ต๋๋ค..! |
@@ -0,0 +1,87 @@
+import re, json, bcrypt
+
+from django.views import View
+from django.http import JsonResponse, request
+from django.db.models.query_utils import Q
+from json.decoder import JSONDecodeError
+
+from user.utils import LoginCheck
+from user.models import User
+
+class SignUpView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ email = data['email']
+ password = data['password']
+ phone = data.get('phone', None)
+ full_name = data.get('full_name', None)
+ user_name = data.get('user_name', None)
+ date_of_birth = data.get('date_of_birth', None)
+
+ if phone:
+ phone = phone.replace('-','')
+
+ REGEX_EMAIL = '^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
+ REGEX_PASSWORD = '\S{8,20}'
+
+ if not re.match(REGEX_EMAIL,email):
+ return JsonResponse({'message':'EMAIL VALIDATION ERROR'}, status=400)
+ if not re.match(REGEX_PASSWORD,password):
+ return JsonResponse({'message':'PASSWORD VALIDATION ERROR'}, status=400)
+
+ if not User.objects.filter(email=email):
+ if phone and User.objects.filter(phone=phone):
+ return JsonResponse({'message':'PHONE ALREADY EXISTS'}, status=400)
+ elif user_name and User.objects.filter(user_name=user_name):
+ return JsonResponse({'message':'USER_NAME ALREADY EXISTS'}, status=400)
+ else:
+ return JsonResponse({'message':'EMAIL ALREADY EXISTS'}, status=400)
+
+ hashed_password = bcrypt.hashpw(password.encode('UTF-8'), bcrypt.gensalt()).decode()
+
+ User.objects.create(
+ email = email,
+ phone = phone,
+ full_name = full_name,
+ user_name = user_name,
+ password = hashed_password,
+ date_of_birth = date_of_birth,
+ )
+
+ return JsonResponse({'message':'SUCCESS'}, status=200)
+
+ except KeyError:
+ return JsonResponse({'message':'KEY ERROR'}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
+
+
+class SignInView(View):
+ def post(self, request):
+ try:
+ data = json.loads(request.body)
+
+ user_id = data['user_id']
+ password = data['password']
+
+ user= User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id))
+
+ if user:
+ stored_password = User.objects.get(Q(user_name=user_id)|Q(email=user_id)|Q(phone=user_id)).password
+ if not bcrypt.checkpw(password.encode('UTF-8'), stored_password.encode('UTF-8')):
+ return JsonResponse({"message":"INVALID_PASSWORD"}, status=401)
+ else:
+ return JsonResponse({"message":"INVALID_USER"}, status=401)
+
+ return JsonResponse({"message":"SUCCESS", "Authorization":LoginCheck(user.id)}, status=200)
+
+ except KeyError:
+ return JsonResponse({"message":"KEY_ERROR"}, status=400)
+ except JSONDecodeError:
+ return JsonResponse({'message':'JSON DECODE ERROR'}, status=400)
+ except Exception as e:
+ print(e)
\ No newline at end of file | Python | ์นํ๋ ํน์ json ๊ด๋ จ exception ์ด JSONDecodeError ์ธ๊ฒ์ผ๊น์..? |
@@ -37,6 +37,8 @@ public PageReviewRes<ReviewRes> getPagedReviewsByTemplestayId(Long templestayId,
throw new TemplestayCoreException(ErrorCode.REVIEW_NOT_FOUND);
}
+ Long count = reviewRepository.countByTempleName(templeName);
+
List<ReviewRes> reviewDtos = reviews.getContent().stream()
.map(review -> new ReviewRes(
review.getId(),
@@ -51,6 +53,7 @@ public PageReviewRes<ReviewRes> getPagedReviewsByTemplestayId(Long templestayId,
return new PageReviewRes<>(
templestayId,
+ count,
page,
size,
reviews.getTotalPages(), | Java | ๋ฆฌ๋ทฐ ์ ์ฒด ๊ฐ์๋ฅผ ๋ฐํํ์ฌ ํ๋ก ํธ์์ ํ์ด์ง ์ฒ๋ฆฌ์ ๋์์ ๋ฐ์ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค! ๊ตฟ |
@@ -0,0 +1,37 @@
+[
+ {
+ "id": 1,
+ "img": "images/yoonhee/imgg.jpg",
+ "text": "ํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ"
+ },
+ {
+ "id": 2,
+ "img": "images/yoonhee/imgg.jpg",
+ "text": "ํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ"
+ },
+ {
+ "id": 3,
+ "img": "images/yoonhee/imgg.jpg",
+ "text": "ํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ"
+ },
+ {
+ "id": 4,
+ "img": "images/yoonhee/imgg.jpg",
+ "text": "ํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ"
+ },
+ {
+ "id": 5,
+ "img": "images/yoonhee/imgg.jpg",
+ "text": "ํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ"
+ },
+ {
+ "id": 6,
+ "img": "images/yoonhee/imgg.jpg",
+ "text": "ํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ"
+ },
+ {
+ "id": 7,
+ "img": "images/yoonhee/imgg.jpg",
+ "text": "ํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ดํ"
+ }
+] | Unknown | ์ ๊ตญ์ ์คํฌ๋์ ๋ป ์ ์๊ฒ ์ต๋๋ค. |
@@ -1,9 +1,23 @@
import React from 'react';
+import './Login.scss';
+import LoginForm from './LoginForm';
-class Login extends React.Component {
+class LoginYoonHee extends React.Component {
render() {
- return null;
+ return (
+ <article className="login-art">
+ <div className="log-in__main">
+ <h1 className="main-name">westagram</h1>
+ <div className="log-in">
+ <LoginForm />
+ </div>
+ <a className="find-ps" href="#!">
+ ๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?
+ </a>
+ </div>
+ </article>
+ );
}
}
-export default Login;
+export default LoginYoonHee; | JavaScript | props์ ๊ฐ๋
์ ๋ํด ์ ์ดํดํ์
จ๋ค์!
ํ์ง๋ง ์ด๋ ๊ฒ ํ ํ์ ์์ด, `<LoginForm>` ์ปดํฌ๋ํธ์์ withRouter importํด์ ๊ฐ์ธ์ฃผ์๋ ๋ฐฉ์์ผ๋ก ํ์๋ ๊ฒ ์ข์ ๊ฒ ๊ฐ๋ค์! |
@@ -0,0 +1,75 @@
+.login-art {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ height: 100vh;
+ background-color: var(--color-boxgray);
+
+ .log-in__main {
+ display: flex;
+ flex-direction: column;
+ justify-content: space-evenly;
+ align-items: center;
+ width: 300px;
+ height: 350px;
+ background-color: white;
+ border: 1px solid var(--color-boxborder);
+ }
+
+ .main-name {
+ font-size: 40px;
+ font-weight: lighter;
+ font-family: 'Lobster', cursive;
+ }
+
+ .log-in {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ }
+
+ .log-in__id,
+ .log-in__ps {
+ width: 230px;
+ height: 35px;
+ margin: 3px 0;
+ padding: 3px 10px;
+ border-radius: 5px;
+ border: 1px solid var(--color-boxborder);
+ color: var(--color-textgray);
+ background-color: var(--color-boxgray);
+ }
+
+ .find-ps {
+ text-decoration: none;
+ font-size: 13px;
+ }
+
+ .log-in__btn {
+ width: 230px;
+ height: 30px;
+ margin-top: 10px;
+ margin-bottom: 80px;
+ border-radius: 5px;
+ background-color: var(--color--btn-text);
+ border: none;
+ color: white;
+ font-weight: bold;
+ }
+ .disabled {
+ width: 230px;
+ height: 30px;
+ margin-top: 10px;
+ margin-bottom: 80px;
+ border-radius: 5px;
+ background-color: var(--color--btn-text-yet);
+ border: none;
+ color: white;
+ font-weight: bold;
+ }
+
+ .log-in > form {
+ display: flex;
+ flex-direction: column;
+ }
+} | Unknown | - ํ๋์ ์์์ ์ฌ๋ฌ๊ฐ์ง ์์ฑ์ ๋ถ์ฌํ๋ ๊ฒฝ์ฐ ์ค์๋, ๊ด๋ จ๋์ ๋ฐ๋ผ์ ๋๋ฆ์ convention์ ์ง์ผ์ ์์ฑํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
- ์ผ๋ฐ์ ์ธ convention ์ ์๋์ ๊ฐ์ต๋๋ค. ์๋์ ๊ฐ์ด ์์ ์ ์ฉํด์ฃผ์ธ์.
[CSS property ์์]
- Layout Properties (position, float, clear, display)
- Box Model Properties (width, height, margin, padding)
- Visual Properties (color, background, border, box-shadow)
- Typography Properties (font-size, font-family, text-align, text-transform)
- Misc Properties (cursor, overflow, z-index)
- ๋ฆฌ๋ทฐํ์ง ์์ ๋ถ๋ถ๋ ์ฐธ๊ณ ํด์ ์์ ํด์ฃผ์ธ์-! |
@@ -0,0 +1,51 @@
+import React from 'react';
+import { withRouter } from 'react-router-dom';
+
+class LoginForm extends React.Component {
+ constructor() {
+ super();
+ this.state = { id: '', ps: '' };
+ }
+
+ goToMain = e => {
+ this.props.history.push('/main-yoonhee');
+ };
+
+ handleInput = e => {
+ this.setState({ [e.target.name]: e.target.value });
+ };
+
+ render() {
+ const { id, ps } = this.state;
+ const isAble = id.includes('@') && ps.length >= 5;
+ return (
+ <form>
+ <input
+ name="id"
+ className="log-in__id"
+ type="text"
+ placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ"
+ onChange={this.handleInput}
+ />
+
+ <input
+ name="ps"
+ className="log-in__ps"
+ type="password"
+ placeholder="๋น๋ฐ๋ฒํธ"
+ onChange={this.handleInput}
+ />
+ <button
+ type="button"
+ className={`log-in__btn ${isAble ? '' : 'disabled'}`}
+ onClick={this.goToMain}
+ disabled={!isAble}
+ >
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+ );
+ }
+}
+
+export default withRouter(LoginForm); | JavaScript | ๊ณ์ฐ๋ ์์ฑ๋ช
์ ํ์ฉํด์ฃผ์
จ๋ค์! :) |
@@ -0,0 +1,10 @@
+import React from 'react';
+
+class Comment extends React.Component {
+ render() {
+ const { innerText } = this.props;
+ return <li>{innerText}</li>;
+ }
+}
+
+export default Comment; | JavaScript | map ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์๋ ๋ถ๋ถ์์ key prop ๋ถ์ฌํด์ฃผ์๋ฉด ๋ฉ๋๋ค! |
@@ -0,0 +1,59 @@
+import React from 'react';
+import Comment from './Comment';
+
+class CommentBox extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = { feedComment: '', commentList: [] };
+ }
+
+ handleInput = e => {
+ this.setState({ [e.target.name]: e.target.value });
+ };
+
+ addCommentByEnter = e => {
+ if (e.key === 'Enter') {
+ this.addComment();
+ }
+ };
+
+ addComment = () => {
+ const { feedComment, commentList } = this.state;
+ this.setState({
+ commentList: [...commentList, feedComment],
+ feedComment: '',
+ });
+ };
+
+ render() {
+ return (
+ <>
+ <div className="feed__comment-box">
+ <input
+ name="feedComment"
+ className="comment__input"
+ placeholder="๋๊ธ ๋ฌ๊ธฐ..."
+ onChange={this.handleInput}
+ onKeyDown={this.addCommentByEnter}
+ value={this.state.feedComment}
+ />
+ <button
+ className="btn btn--hover comment__btn"
+ onClick={this.addComment}
+ >
+ ๊ฒ์
+ </button>
+ </div>
+ <div className="feed__comment">
+ <ul className="feed__comment-list">
+ {this.state.commentList.map((comment, index) => {
+ return <Comment key={index} innerText={comment} />;
+ })}
+ </ul>
+ </div>
+ </>
+ );
+ }
+}
+
+export default CommentBox; | JavaScript | isKeyEnter๋ผ๋ ํจ์๋ช
์ key๊ฐ enter์ธ์ง ์๋์ง๋ฅผ ํ๋ณํ๋ boolean ๋ณ์๋ช
์ผ๋ก ์ ํฉํ ๊ฒ ๊ฐ๋ค์.
ํจ์์ ๋์์ ๋ํ ๋ด์ฉ์ ์ง๊ด์ ์ผ๋ก ์ ์ ์๋ ๋์ฌํ์ผ๋ก ์์ฑํด์ฃผ์ธ์!
ex) addCommentByEnter |
@@ -0,0 +1,59 @@
+import React from 'react';
+import Comment from './Comment';
+
+class CommentBox extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = { feedComment: '', commentList: [] };
+ }
+
+ handleInput = e => {
+ this.setState({ [e.target.name]: e.target.value });
+ };
+
+ addCommentByEnter = e => {
+ if (e.key === 'Enter') {
+ this.addComment();
+ }
+ };
+
+ addComment = () => {
+ const { feedComment, commentList } = this.state;
+ this.setState({
+ commentList: [...commentList, feedComment],
+ feedComment: '',
+ });
+ };
+
+ render() {
+ return (
+ <>
+ <div className="feed__comment-box">
+ <input
+ name="feedComment"
+ className="comment__input"
+ placeholder="๋๊ธ ๋ฌ๊ธฐ..."
+ onChange={this.handleInput}
+ onKeyDown={this.addCommentByEnter}
+ value={this.state.feedComment}
+ />
+ <button
+ className="btn btn--hover comment__btn"
+ onClick={this.addComment}
+ >
+ ๊ฒ์
+ </button>
+ </div>
+ <div className="feed__comment">
+ <ul className="feed__comment-list">
+ {this.state.commentList.map((comment, index) => {
+ return <Comment key={index} innerText={comment} />;
+ })}
+ </ul>
+ </div>
+ </>
+ );
+ }
+}
+
+export default CommentBox; | JavaScript | ๋ฆฌ๋ทฐํ์ง ์์ ๋ถ๋ถ๋ ์์ ํด์ฃผ์ธ์! |
@@ -0,0 +1,59 @@
+import React from 'react';
+import Comment from './Comment';
+
+class CommentBox extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = { feedComment: '', commentList: [] };
+ }
+
+ handleInput = e => {
+ this.setState({ [e.target.name]: e.target.value });
+ };
+
+ addCommentByEnter = e => {
+ if (e.key === 'Enter') {
+ this.addComment();
+ }
+ };
+
+ addComment = () => {
+ const { feedComment, commentList } = this.state;
+ this.setState({
+ commentList: [...commentList, feedComment],
+ feedComment: '',
+ });
+ };
+
+ render() {
+ return (
+ <>
+ <div className="feed__comment-box">
+ <input
+ name="feedComment"
+ className="comment__input"
+ placeholder="๋๊ธ ๋ฌ๊ธฐ..."
+ onChange={this.handleInput}
+ onKeyDown={this.addCommentByEnter}
+ value={this.state.feedComment}
+ />
+ <button
+ className="btn btn--hover comment__btn"
+ onClick={this.addComment}
+ >
+ ๊ฒ์
+ </button>
+ </div>
+ <div className="feed__comment">
+ <ul className="feed__comment-list">
+ {this.state.commentList.map((comment, index) => {
+ return <Comment key={index} innerText={comment} />;
+ })}
+ </ul>
+ </div>
+ </>
+ );
+ }
+}
+
+export default CommentBox; | JavaScript | - `newfeedComment`๋ผ๊ณ ์๋ก ์ ์ธํ๊ณ ํ ๋นํ ํ์ ์์ด, concat ๋ฉ์๋์ feedComment๋ผ๋ state๋ฅผ ์ง์ ๋ฃ์ด์ฃผ์
๋ ๋ ๊ฒ ๊ฐ๋ค์.
- concat ์ ์ฌ์ฉํด์ฃผ์
จ๋๋ฐ, concat ๋์ ์ spread operator๋ฅผ ์ฌ์ฉํด์ ๋์ผํ๊ฒ ๊ตฌํํด๋ณด์ค ์ ์์ต๋๋ค.
์ฐ์ตํ๋ค๊ณ ์๊ฐํ์๊ณ ์ฐพ์์ ๊ตฌํํด๋ณด์ธ์!
```suggestion
const { feedComment, commentList } = this.state;
this.setState({
commentList: commentList.concat(feedComment),
feedComment: '',
});
``` |
@@ -0,0 +1,59 @@
+import React from 'react';
+import Comment from './Comment';
+
+class CommentBox extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = { feedComment: '', commentList: [] };
+ }
+
+ handleInput = e => {
+ this.setState({ [e.target.name]: e.target.value });
+ };
+
+ addCommentByEnter = e => {
+ if (e.key === 'Enter') {
+ this.addComment();
+ }
+ };
+
+ addComment = () => {
+ const { feedComment, commentList } = this.state;
+ this.setState({
+ commentList: [...commentList, feedComment],
+ feedComment: '',
+ });
+ };
+
+ render() {
+ return (
+ <>
+ <div className="feed__comment-box">
+ <input
+ name="feedComment"
+ className="comment__input"
+ placeholder="๋๊ธ ๋ฌ๊ธฐ..."
+ onChange={this.handleInput}
+ onKeyDown={this.addCommentByEnter}
+ value={this.state.feedComment}
+ />
+ <button
+ className="btn btn--hover comment__btn"
+ onClick={this.addComment}
+ >
+ ๊ฒ์
+ </button>
+ </div>
+ <div className="feed__comment">
+ <ul className="feed__comment-list">
+ {this.state.commentList.map((comment, index) => {
+ return <Comment key={index} innerText={comment} />;
+ })}
+ </ul>
+ </div>
+ </>
+ );
+ }
+}
+
+export default CommentBox; | JavaScript | ์ด ์ปดํฌ๋ํธ์ tag๋ค์์ id์ className์ ๊ฐ์ด ๋ถ์ฌํ์ ์ด์ ๊ฐ ์์๊น์?? |
@@ -0,0 +1,59 @@
+import React from 'react';
+import Comment from './Comment';
+
+class CommentBox extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = { feedComment: '', commentList: [] };
+ }
+
+ handleInput = e => {
+ this.setState({ [e.target.name]: e.target.value });
+ };
+
+ addCommentByEnter = e => {
+ if (e.key === 'Enter') {
+ this.addComment();
+ }
+ };
+
+ addComment = () => {
+ const { feedComment, commentList } = this.state;
+ this.setState({
+ commentList: [...commentList, feedComment],
+ feedComment: '',
+ });
+ };
+
+ render() {
+ return (
+ <>
+ <div className="feed__comment-box">
+ <input
+ name="feedComment"
+ className="comment__input"
+ placeholder="๋๊ธ ๋ฌ๊ธฐ..."
+ onChange={this.handleInput}
+ onKeyDown={this.addCommentByEnter}
+ value={this.state.feedComment}
+ />
+ <button
+ className="btn btn--hover comment__btn"
+ onClick={this.addComment}
+ >
+ ๊ฒ์
+ </button>
+ </div>
+ <div className="feed__comment">
+ <ul className="feed__comment-list">
+ {this.state.commentList.map((comment, index) => {
+ return <Comment key={index} innerText={comment} />;
+ })}
+ </ul>
+ </div>
+ </>
+ );
+ }
+}
+
+export default CommentBox; | JavaScript | ์์ ๋ฆฌ๋ทฐ๋๋ฆฐ ๋ด์ฉ์ด๋ค์! index๋ฅผ props๋ก ๋๊ฒจ์ฃผ๋ ๊ฒ ์๋๋ผ, ์ด ๋ถ๋ถ์์ key={index}๋ก ๋ถ์ฌํด์ฃผ์๋ฉด ๋ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,59 @@
+import React from 'react';
+import Comment from './Comment';
+
+class CommentBox extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = { feedComment: '', commentList: [] };
+ }
+
+ handleInput = e => {
+ this.setState({ [e.target.name]: e.target.value });
+ };
+
+ addCommentByEnter = e => {
+ if (e.key === 'Enter') {
+ this.addComment();
+ }
+ };
+
+ addComment = () => {
+ const { feedComment, commentList } = this.state;
+ this.setState({
+ commentList: [...commentList, feedComment],
+ feedComment: '',
+ });
+ };
+
+ render() {
+ return (
+ <>
+ <div className="feed__comment-box">
+ <input
+ name="feedComment"
+ className="comment__input"
+ placeholder="๋๊ธ ๋ฌ๊ธฐ..."
+ onChange={this.handleInput}
+ onKeyDown={this.addCommentByEnter}
+ value={this.state.feedComment}
+ />
+ <button
+ className="btn btn--hover comment__btn"
+ onClick={this.addComment}
+ >
+ ๊ฒ์
+ </button>
+ </div>
+ <div className="feed__comment">
+ <ul className="feed__comment-list">
+ {this.state.commentList.map((comment, index) => {
+ return <Comment key={index} innerText={comment} />;
+ })}
+ </ul>
+ </div>
+ </>
+ );
+ }
+}
+
+export default CommentBox; | JavaScript | ๊ทธ๋ฆฌ๊ณ cur์ด๋ผ๋ ๋ณ์๋ช
์ ์ด๋ค ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ง๊ณ ์๋์ง ๋ช
ํํ์ง ์์๋ฐ, ํด๋น ๋ณ์๊ฐ ๋ด๊ณ ์๋ ๋ฐ์ดํฐ์ ๋ํ ๋ด์ฉ์ด ์ข ๋ ์ง๊ด์ ์ผ๋ก ๋๋ฌ๋ ์ ์๋๋ก ์์ ํด์ฃผ์ธ์!
ex) comment |
@@ -0,0 +1,32 @@
+import React from 'react';
+import Feed from './Feed';
+
+class Feeds extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ feeds: [],
+ };
+ }
+
+ componentDidMount() {
+ fetch('/data/feed.json')
+ .then(res => res.json())
+ .then(data => {
+ this.setState({ feeds: data });
+ });
+ }
+
+ render() {
+ const { feeds } = this.state;
+ return (
+ <div className="feeds">
+ {feeds.map(feed => (
+ <Feed key={feed.id} img={feed.img} text={feed.text} />
+ ))}
+ </div>
+ );
+ }
+}
+
+export default Feeds; | JavaScript | - method ์ ์๋ตํด์ฃผ์
จ๋ค์! ๐
- ์ถ๊ฐ์ ์ผ๋ก, `http://localhost:3000` ๋ถ๋ถ๋ ์๋ตํ ์ ์์ต๋๋ค. ํฌํธ ๋ฒํธ๊ฐ ๋ฐ๋ ๋๋ง๋ค ์๋ฌ๊ฐ ๋ฐ์ํ๊ณ ๊ทธ๋๊ทธ๋ ์์ ํด์ค์ผ ํ๋ ๋ฒ๊ฑฐ๋ก์์ด ์๊ธฐ ๋๋ฌธ์, ๋ค์๊ณผ ๊ฐ์ด ์๋ตํด์ ์ฌ์ฉํด์ฃผ์ธ์!
```suggestion
fetch('/data/feed.json')
``` |
@@ -0,0 +1,32 @@
+import React from 'react';
+import Feed from './Feed';
+
+class Feeds extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ feeds: [],
+ };
+ }
+
+ componentDidMount() {
+ fetch('/data/feed.json')
+ .then(res => res.json())
+ .then(data => {
+ this.setState({ feeds: data });
+ });
+ }
+
+ render() {
+ const { feeds } = this.state;
+ return (
+ <div className="feeds">
+ {feeds.map(feed => (
+ <Feed key={feed.id} img={feed.img} text={feed.text} />
+ ))}
+ </div>
+ );
+ }
+}
+
+export default Feeds; | JavaScript | ์ค์ ์ฌ๊ธฐ์๋ key prop ์ ๋ถ์ฌํด์ฃผ์
จ๋ค์!
์ด์ง ํ ์ ์ก์๋ฉด,, ๋งค๊ฐ๋ณ์์ ๋ฐ์ดํฐ๋ ๊ฐ ํผ๋์ ๋ํ ๋ฐ์ดํฐ์ด๊ธฐ ๋๋ฌธ์ feeds -> feed๊ฐ ๋ ์ ์ ํ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -1,9 +1,22 @@
+// eslint-disable-next-line
import React from 'react';
+import Nav from './Nav';
+import Feeds from './Feeds';
+import MainR from './MainR';
+import './Main.scss';
-class Main extends React.Component {
+class MainYoonHee extends React.Component {
render() {
- return null;
+ return (
+ <div className="main-body">
+ <Nav />
+ <main>
+ <Feeds />
+ <MainR />
+ </main>
+ </div>
+ );
}
}
-export default Main;
+export default MainYoonHee; | JavaScript | import ์์ ์์ ํด์ฃผ์ธ์! ์ผ๋ฐ์ ์ธ convention์ ๋ฐ๋ผ ์์๋ง ์ ์ง์ผ์ฃผ์
๋ ๊ฐ๋
์ฑ์ด ์ข์์ง๋๋ค. ์๋ ์์ ์ฐธ๊ณ ํด์ฃผ์ธ์.
- React โ Library(Package) โ Component โ ๋ณ์ / ์ด๋ฏธ์ง โ css ํ์ผ(scss ํ์ผ) |
@@ -0,0 +1,25 @@
+import React from 'react';
+
+class Recommend extends React.Component {
+ render() {
+ const { nickname, img } = this.props;
+ return (
+ <li className="user main-right__user2">
+ <div className="user-and-botton">
+ <img
+ className="user__img user__img--brder-red"
+ alt={nickname}
+ src={img}
+ />
+ <div className="user-id2">
+ <div className="user__id">{nickname}</div>
+ <div className="text--gray">ํ๊ตญ์ดํ๊ตญ์ดํ๊ตญ์ด</div>
+ </div>
+ </div>
+ <button className="btn btn--hover nnn">ํ๋ก์ฐ</button>
+ </li>
+ );
+ }
+}
+
+export default Recommend; | JavaScript | `<li>`ํ๊ทธ, `<div>`ํ๊ทธ ๋ ์ค ํ๋๋ก๋ง ๊ฐ์ธ์ฃผ์
๋ ๋ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,22 @@
+import React from 'react';
+
+class Story extends React.Component {
+ render() {
+ const { nickname, img } = this.props;
+ return (
+ <li className="user main-right__user">
+ <img
+ className="user__img user__img--brder-red"
+ alt={nickname}
+ src={img}
+ />
+ <div className="user-id2">
+ <div className="user__id">{nickname}</div>
+ <div className="text--gray">2์๊ฐ ์ </div>
+ </div>
+ </li>
+ );
+ }
+}
+
+export default Story; | JavaScript | ์ฌ๊ธฐ๋ ๋ง์ฐฌ๊ฐ์ง-! |
@@ -0,0 +1,281 @@
+/*------๊ณตํต-----*/
+/*------๊ณตํต-----*/
+
+.main-body {
+ background-color: var(--color-boxgray);
+}
+
+main {
+ display: flex;
+ margin-left: 100px;
+}
+
+ul > li {
+ margin: 10px 0;
+}
+
+a {
+ text-decoration: none;
+ color: inherit;
+}
+
+.box {
+ background-color: white;
+ border: 1px solid var(--color-boxborder);
+}
+.box-padding {
+ padding: 10px;
+}
+
+.text {
+ font-size: 12px;
+}
+
+.text--gray {
+ margin-top: 3px;
+ font-size: 13px;
+ color: var(--color-textgray);
+}
+
+.icon {
+ border: no;
+}
+
+.btn {
+ padding: 5px 0px;
+ border: none;
+ border-radius: 5px;
+ background-color: transparent;
+ color: var(--color--btn-text);
+ font-weight: bold;
+}
+.btn--hover:hover {
+ color: white;
+ background-color: var(--color--btn-text);
+}
+
+.westagram {
+ font-family: 'Lobster', cursive;
+ font-size: 25px;
+}
+.user {
+ display: flex;
+ align-items: center;
+ justify-content: flex-start;
+}
+
+.user__img {
+ width: 30px;
+ height: 30px;
+ margin-right: 7px;
+ border-radius: 50%;
+ border: 1px solid var(--color-textgray);
+}
+
+.user__img--brder-red {
+ border: 1px solid red;
+ border-spacing: 3px;
+}
+
+.user__img--small {
+ width: 20px;
+ height: 18px;
+ margin-right: 5px;
+}
+
+.user__img--big {
+ width: 40px;
+ height: 40px;
+}
+
+.user__id {
+ font-size: 14px;
+ font-weight: bolder;
+}
+
+.user-text2 {
+ display: flex;
+ flex-direction: column;
+}
+
+.footer {
+ margin-top: 15px;
+}
+
+/*--------nav--------*/
+/*--------nav--------*/
+/*--------nav--------*/
+
+.nav {
+ display: flex;
+ justify-content: space-around;
+ align-items: center;
+ padding: 20px 0;
+ border-bottom: 1px solid var(--color-boxborder);
+ background-color: white;
+
+ .nav__border {
+ height: 30px;
+ border-left: 2px solid black;
+ }
+
+ .nav-left {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ width: 18%;
+ }
+
+ .nav-center {
+ width: 20%;
+ }
+
+ .nav-center > .search-bar {
+ height: 25px;
+ width: 100%;
+ border: 1px solid var(--color-boxborder);
+ background-color: var(--color-boxgray);
+ text-align: center;
+ }
+ .search-bar[value] {
+ color: var(--color-textgray);
+ }
+
+ .nav-right {
+ display: flex;
+ justify-content: space-between;
+ width: 12%;
+ }
+}
+
+/*----------feed----------*/
+/*----------feed----------*/
+/*----------feed----------*/
+
+.feeds {
+ display: flex;
+ flex-direction: column;
+ width: 50%;
+ padding-top: 65px;
+
+ .feed {
+ display: flex;
+ align-items: center;
+ flex-direction: column;
+ width: 100%;
+ margin-bottom: 50px;
+ border: 1px solid var(--color-boxborder);
+ background-color: white;
+ }
+
+ .feed__head {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ width: 95%;
+ margin: 15px 20px;
+ }
+
+ .feed__head > .user {
+ width: 22%;
+ }
+
+ .feed__img {
+ width: 100%;
+ }
+
+ .feed__icons {
+ display: flex;
+ justify-content: space-between;
+ width: 95%;
+ margin: 12px 0px;
+ }
+
+ .feed__icons__left {
+ display: flex;
+ justify-content: space-between;
+ width: 18%;
+ }
+
+ .feed__likes {
+ display: flex;
+ align-items: center;
+ width: 95%;
+ }
+
+ .feed__text {
+ width: 95%;
+ margin-top: 15px;
+ }
+
+ .feed__comment-box {
+ width: 100%;
+ height: 35px;
+ margin-top: 5px;
+ border-top: 1px solid var(--color-boxborder);
+ border-bottom: 1px solid var(--color-boxborder);
+ }
+
+ .comment__input {
+ width: 90%;
+ height: 100%;
+ padding-left: 14px;
+ border: none;
+ }
+
+ .comment__input[placehilder] {
+ color: var(--color-textgray);
+ }
+
+ .comment__btn {
+ width: 8%;
+ height: 80;
+ }
+
+ .feed__comment {
+ width: 100%;
+ }
+ .feed__comment-list {
+ width: 95%;
+ margin: 10px 0;
+ padding: 5px 14px;
+ }
+
+ .feed__comment-list > li {
+ font-size: 13px;
+ }
+}
+
+/*-------------main-right------------*/
+/*-------------main-right------------*/
+/*-------------main-right------------*/
+
+.main-right {
+ position: fixed;
+ right: 40px;
+ width: 25%;
+ margin-top: 65px;
+
+ .main-right__header {
+ display: flex;
+ align-items: flex-end;
+ justify-content: space-between;
+ margin-bottom: 15px;
+ padding: 0 5px;
+ }
+
+ .user-and-botton {
+ width: 70%;
+ display: flex;
+ }
+
+ .main-right__story > .box {
+ margin-top: 15px;
+ }
+
+ .main-right__user2 {
+ display: flex;
+ justify-content: space-between;
+ margin: 2px;
+ }
+} | Unknown | ๊ณตํต์ผ๋ก ์ฌ์ฉํ๋ ์์ฑ์ ํ์๋ค๊ณผ ์์ํ์ฌ common.scss ํ์ผ๋ก ์ฎ๊ฒจ์ฃผ์ธ์! |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.