Ubuntu

first commit

Showing 49 changed files with 729 additions and 0 deletions
1 +# DropBox Project using AWS, Khuloud
2 +
3 +### 경희대학교 Cloud Computing A조
4 +
5 +## 팀원
6 +
7 +- 2017110267 강연욱
8 +
9 +- 2017103972 김성연
10 +
11 +- 2017100907 유정수
12 +
13 +- 2017104025 정수연
14 +
15 +- 2016104173 최재혁
16 +
17 +## 기술 Stack
18 +1. Frontend: nuxt, vuetify
19 +2. Backend : Django
20 +3. Database: DynamoDB
21 +4. A W S : EC2, S3
22 +
23 +## 향후 일정
...\ No newline at end of file ...\ No newline at end of file
No preview for this file type
1 +# -*- coding: utf-8 -*-
2 +from __future__ import unicode_literals
3 +
4 +from django.contrib import admin
5 +
6 +# Register your models here.
No preview for this file type
1 +# -*- coding: utf-8 -*-
2 +from __future__ import unicode_literals
3 +
4 +from django.apps import AppConfig
5 +
6 +
7 +class BlogConfig(AppConfig):
8 + name = 'blog'
No preview for this file type
1 +import boto3
2 +import configparser
3 +
4 +config = configparser.ConfigParser()
5 +config.read('config.ini')
6 +
7 +
8 +
9 +class Cognito():
10 + region = config['cognito']['region']
11 + user_pool_id = config['cognito']['user_pool_id']
12 + app_client_id = config['cognito']['app_client_id']
13 + identity_pool_id = config['cognito']['identity_pool_id']
14 + account_id = config['cognito']['account_id']
15 + token = ''
16 +
17 + def sign_up(self, username, password, UserAttributes):
18 + client = boto3.client('cognito-idp', self.region,
19 + aws_access_key_id=config['aws']['AWS_ACCESS_KEY_ID'],
20 + aws_secret_access_key=config['aws']['AWS_SECRET_ACCESS_KEY'])
21 +
22 + response = client.sign_up(ClientId=self.app_client_id,
23 + Username=username,
24 + Password=password,
25 + UserAttributes=UserAttributes)
26 + return response
27 +
28 + def confirm_sign_up(self, username):
29 + client = boto3.client('cognito-idp', self.region,
30 + aws_access_key_id=config['aws']['AWS_ACCESS_KEY_ID'],
31 + aws_secret_access_key=config['aws']['AWS_SECRET_ACCESS_KEY'])
32 +
33 + response = client.admin_confirm_sign_up(UserPoolId=self.user_pool_id, Username=username)
34 + return response
35 +
36 + def sign_in_admin(self, username, password):
37 + # Get ID Token
38 + idp_client = boto3.client('cognito-idp', self.region,
39 + aws_access_key_id=config['aws']['AWS_ACCESS_KEY_ID'],
40 + aws_secret_access_key=config['aws']['AWS_SECRET_ACCESS_KEY'])
41 +
42 + response = idp_client.admin_initiate_auth(UserPoolId=self.user_pool_id,
43 + ClientId=self.app_client_id,
44 + AuthFlow='ADMIN_NO_SRP_AUTH',
45 + AuthParameters={'USERNAME': username,'PASSWORD': password})
46 +
47 + provider = 'cognito-idp.%s.amazonaws.com/%s' % (self.region, self.user_pool_id)
48 + self.token = response['AuthenticationResult']['IdToken']
49 +
50 + # Get IdentityId
51 + ci_client = boto3.client('cognito-identity', self.region,
52 + aws_access_key_id=config['aws']['AWS_ACCESS_KEY_ID'],
53 + aws_secret_access_key=config['aws']['AWS_SECRET_ACCESS_KEY'])
54 +
55 + response = ci_client.get_id(AccountId=self.account_id,
56 + IdentityPoolId=self.identity_pool_id,
57 + Logins={provider: self.token})
58 +
59 + # Get Credentials
60 + response = ci_client.get_credentials_for_identity(IdentityId=response['IdentityId'], Logins={provider: self.token})
61 + return response
1 +# -*- coding: utf-8 -*-
2 +from __future__ import unicode_literals
3 +
4 +from django.db import models
5 +
6 +# Create your models here.
No preview for this file type
1 +<!DOCTYPE html>
2 +<html lang="en">
3 +<head>
4 + <meta charset="UTF-8">
5 + <title>{% block title %}{% endblock%}</title>
6 +</head>
7 +<body>
8 + {% block content %}{% endblock %}
9 +</body>
10 +</html>
...\ No newline at end of file ...\ No newline at end of file
1 +<h1>
2 + hi!
3 +</h1>
...\ No newline at end of file ...\ No newline at end of file
1 +<!DOCTYPE html>
2 +<html lang="en">
3 +<head>
4 + <meta charset="utf-8">
5 + <meta http-equiv="X-UA-Compatible" content="IE=edge">
6 +
7 + <title>KHUropBox</title>
8 +
9 + <script src="/static/js/app.js"></script>
10 + <script src="/static/js/aws-sdk.min.js"></script>
11 +
12 + <link href="/static/css/app.css" rel="stylesheet">
13 + <link href="/static/css/common.css" rel="stylesheet">
14 + <link href="/static/css/override.css" rel="stylesheet">
15 + <link href="/static/css/layout.css" rel="stylesheet">
16 + <link href="/static/css/filebrowser.css" rel="stylesheet">
17 + <link href="/static/css/font-awesome.min.css" rel="stylesheet">
18 +
19 +
20 +</head>
21 +<body>
22 + <div id="wrapper">
23 + <div id="page-content-wrapper">
24 +
25 + <div id="header">
26 + <div id="logo">
27 + <a href="/"></a>
28 + </div>
29 + </div>
30 +
31 + <div id="content">
32 + {% block content %}
33 + {% endblock %}
34 + </div>
35 + </div>
36 + </div>
37 +
38 +</body>
...\ No newline at end of file ...\ No newline at end of file
1 +{% extends 'layout.html' %}
2 +
3 +{% block content %}
4 +
5 + <div class="col-md-8 col-md-offset-2">
6 + <div class="panel panel-default">
7 + <div class="panel-heading">로그인</div>
8 + <div class="panel-body">
9 + <form class="form-horizontal" role="form" method="POST" action="/login/">
10 +
11 + {% csrf_token %}
12 + <div class="form-group">
13 + <div class="col-md-12">
14 + <label for="userid">아이디</label>
15 + <input id="userid" type="userid" class="form-control" name="username" required autofocus>
16 + </div>
17 + </div>
18 +
19 + <div class="form-group">
20 + <div class="col-md-12">
21 + <label for="password">비밀번호</label>
22 + <input id="password" type="password" class="form-control" name="password" required>
23 + </div>
24 + </div>
25 +
26 + <div class="form-group">
27 + <div class="col-md-12">
28 + <button type="submit" class="btn btn-success">
29 + 로그인
30 + </button>
31 + <button class="btn btn-success" onclick="location.href='/register/';">
32 + 회원가입
33 + </button>
34 + </div>
35 + </div>
36 +
37 + <div class="form-group">
38 + <div class="col-md-12 text-center">
39 + <h5>{{ message }}</h5>
40 + </div>
41 + </div>
42 +
43 + </form>
44 + </div>
45 + </div>
46 + </div>
47 +
48 +{% endblock %}
...\ No newline at end of file ...\ No newline at end of file
1 +{% extends 'layout.html' %}
2 +
3 +{% block content %}
4 +
5 + <div class="col-md-8 col-md-offset-2">
6 + <div class="panel panel-default">
7 +
8 + <div class="panel-body">
9 + <form class="form-horizontal" role="form" method="POST" action="/register/">
10 + {% csrf_token %}
11 +
12 + <div class="form-group">
13 + <div class="col-md-12">
14 + <label for="username"><span style="color:green;">아이디</span></label>
15 + <input id="username" type="text" class="form-control" name="username" required autofocus>
16 + </div>
17 + </div>
18 +
19 + <div class="form-group">
20 + <div class="col-md-12">
21 + <label for="email"><span style="color:green;">이메일</span><h6 style="display:inline;"> - 비밀번호 분실시 사용됩니다.</h6></label>
22 + <input id="email" type="email" class="form-control" name="email" required>
23 + </div>
24 + </div>
25 +
26 + <div class="form-group">
27 + <div class="col-md-12">
28 + <label for="password"><span style="color:green;">비밀번호</span><h6 style="display:inline;"> - 비밀번호는 6자리 이상으로 설정되어야 합니다.</h6></label>
29 + <input id="password" type="password" class="form-control" name="password" required>
30 + </div>
31 + </div>
32 +
33 + <div class="form-group">
34 + <div class="col-md-12">
35 + <label for="first_name"><span style="color:green;"></span></label>
36 + <input id="first_name" type="first_name" class="form-control" name="first_name" required>
37 + </div>
38 + </div>
39 + <div class="form-group">
40 + <div class="col-md-12">
41 + <label for="last_name"><span style="color:green;">이름</span></label>
42 + <input id="last_name" type="last_name" class="form-control" name="last_name" required>
43 + </div>
44 + </div>
45 +
46 + <div class="form-group">
47 + <div class="col-md-12">
48 + <button type="submit" class="btn btn-success">회원가입</button>
49 + </div>
50 + </div>
51 +
52 + <div class="form-group">
53 + <div class="col-md-12 text-center">
54 + <h6>{{ message }}</h6>
55 + </div>
56 + </div>
57 +
58 + </form>
59 + </div>
60 + </div>
61 + </div>
62 +
63 +{% endblock %}
...\ No newline at end of file ...\ No newline at end of file
1 +# -*- coding: utf-8 -*-
2 +from __future__ import unicode_literals
3 +
4 +from django.test import TestCase
5 +
6 +# Create your tests here.
1 +from django.contrib.auth.models import User
2 +from django.contrib.auth import authenticate
3 +from django.shortcuts import render, redirect
4 +from django.core.exceptions import PermissionDenied
5 +from khuloud import settings
6 +from khuloud import cognito
7 +from django.views.decorators.csrf import csrf_exempt
8 +import hashlib
9 +
10 +import django
11 +
12 +
13 +def index(request):
14 + if request.user.is_authenticated:
15 + return render(request, "main.html")
16 + else:
17 + return render(request, "login.html")
18 +
19 +def login(request):
20 + if request.method == "POST":
21 + if not all(i in request.POST for i in ('username', 'password')):
22 + return render(request, "login.html", {
23 + "message": "please enter id and passowrd"
24 + })
25 +
26 + un = request.POST['username']
27 + pw = request.POST['password']
28 +
29 + user = authenticate(username=un, password=pw)
30 +
31 + if user is not None:
32 + auth = django.contrib.auth.login(request, user)
33 +
34 + hashcode = hashlib.md5(request.POST['password'].encode('utf-8')).hexdigest()
35 +
36 + cog = cognito.Cognito()
37 + cog.sign_in_admin(username=un, password=hashcode)
38 +
39 + return redirect('/')
40 + else:
41 + return render(request, "login.html", {
42 + "message": "check id and password"
43 + })
44 + else:
45 + return render(request, "login.html")
46 +
47 +def logout(request):
48 + if request.user.is_authenticated:
49 + django.contrib.auth.logout(request)
50 +
51 + return redirect("/")
52 +
53 +def register(request):
54 + Cog = cognito.Cognito()
55 + if request.method == "POST":
56 + require_keys = ('username', 'password', 'first_name', 'last_name', 'email')
57 + if all(i in request.POST for i in require_keys):
58 + if User.objects.filter(username=request.POST['username']).count():
59 + return render(request, 'register.html', {
60 + "message": 'alreay exist id!'
61 + })
62 + if User.objects.filter(email=request.POST['email']).count():
63 + return render(request, 'register.html', {
64 + "message": 'already exist email'
65 + })
66 +
67 + userobj = User.objects.create_user(
68 + username=request.POST['username'],
69 + password=request.POST['password'],
70 + first_name=request.POST['first_name'],
71 + last_name=request.POST['last_name'],
72 + email=request.POST['email']
73 + )
74 +
75 + hashcode = hashlib.md5(request.POST['password'].encode('utf-8')).hexdigest()
76 +
77 + Cog.sign_up(
78 + username=request.POST['username'],
79 + password=hashcode,
80 + UserAttributes=[
81 + {
82 + 'Name' : 'email',
83 + 'Value' : request.POST['email'],
84 + },
85 + {
86 + 'Name' : 'family_name',
87 + 'Value': request.POST['first_name'],
88 + },
89 + {
90 + 'Name' : 'given_name',
91 + 'Value': request.POST['last_name'],
92 + },
93 + ])
94 +
95 + Cog.confirm_sign_up(username=request.POST['username']);
96 +
97 + return redirect('/')
98 + else:
99 + return render(request, 'register.html', {
100 + "message": 'erroe!'
101 + })
102 + else:
103 + return render(request, 'register.html')
No preview for this file type
No preview for this file type
1 +import boto3
2 +dynamodb = boto3.resource('dynamodb')
3 +table = dynamodb.Table('users')
4 +
5 +table.put_item(
6 +
7 + Item={
8 +
9 + 'username': 'janedoe',
10 +
11 + 'first_name': 'Jane',
12 +
13 + 'last_name': 'Doe',
14 +
15 + 'age': 25,
16 +
17 + 'account_type': 'standard_user',
18 +
19 + }
20 +
21 +)
22 +
23 +
No preview for this file type
No preview for this file type
1 +"""
2 +Django settings for khuloud project.
3 +
4 +Generated by 'django-admin startproject' using Django 1.11.29.
5 +
6 +For more information on this file, see
7 +https://docs.djangoproject.com/en/1.11/topics/settings/
8 +
9 +For the full list of settings and their values, see
10 +https://docs.djangoproject.com/en/1.11/ref/settings/
11 +"""
12 +
13 +import os
14 +
15 +# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16 +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17 +
18 +
19 +# Quick-start development settings - unsuitable for production
20 +# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
21 +
22 +# SECURITY WARNING: keep the secret key used in production secret!
23 +SECRET_KEY = 'g%eiz-f9vp&g-%12ez#6n57sw60maf7oc^p)0-$jd4n^4grx(l'
24 +
25 +# SECURITY WARNING: don't run with debug turned on in production!
26 +DEBUG = True
27 +
28 +ALLOWED_HOSTS = [
29 + 'localhost',
30 + '.ap-northeast-2.compute.amazonaws.com',
31 +]
32 +
33 +
34 +# Application definition
35 +
36 +INSTALLED_APPS = [
37 + 'django.contrib.admin',
38 + 'django.contrib.auth',
39 + 'django.contrib.contenttypes',
40 + 'django.contrib.sessions',
41 + 'django.contrib.messages',
42 + 'django.contrib.staticfiles',
43 + 'blog.apps.BlogConfig',
44 + 'login.apps.LoginConfig',
45 +]
46 +
47 +MIDDLEWARE = [
48 + 'django.middleware.security.SecurityMiddleware',
49 + 'django.contrib.sessions.middleware.SessionMiddleware',
50 + 'django.middleware.common.CommonMiddleware',
51 + 'django.middleware.csrf.CsrfViewMiddleware',
52 + 'django.contrib.auth.middleware.AuthenticationMiddleware',
53 + 'django.contrib.messages.middleware.MessageMiddleware',
54 + 'django.middleware.clickjacking.XFrameOptionsMiddleware',
55 +]
56 +
57 +ROOT_URLCONF = 'khuloud.urls'
58 +
59 +TEMPLATES = [
60 + {
61 + 'BACKEND': 'django.template.backends.django.DjangoTemplates',
62 + 'DIRS': [],
63 + 'APP_DIRS': True,
64 + 'OPTIONS': {
65 + 'context_processors': [
66 + 'django.template.context_processors.debug',
67 + 'django.template.context_processors.request',
68 + 'django.contrib.auth.context_processors.auth',
69 + 'django.contrib.messages.context_processors.messages',
70 + ],
71 + },
72 + },
73 +]
74 +
75 +WSGI_APPLICATION = 'khuloud.wsgi.application'
76 +
77 +
78 +# Database
79 +# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
80 +
81 +DATABASES = {
82 + 'default': {
83 + 'ENGINE': 'django.db.backends.sqlite3',
84 + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
85 + }
86 +}
87 +
88 +
89 +# Password validation
90 +# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
91 +
92 +AUTH_PASSWORD_VALIDATORS = [
93 + {
94 + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
95 + },
96 + {
97 + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
98 + },
99 + {
100 + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
101 + },
102 + {
103 + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
104 + },
105 +]
106 +
107 +
108 +# Internationalization
109 +# https://docs.djangoproject.com/en/1.11/topics/i18n/
110 +
111 +LANGUAGE_CODE = 'en-us'
112 +
113 +TIME_ZONE = 'Asia/Seoul'
114 +
115 +USE_I18N = True
116 +
117 +USE_L10N = True
118 +
119 +USE_TZ = True
120 +
121 +
122 +# Static files (CSS, JavaScript, Images)
123 +# https://docs.djangoproject.com/en/1.11/howto/static-files/
124 +
125 +STATIC_URL = '/static/'
No preview for this file type
1 +"""khuloud URL Configuration
2 +
3 +The `urlpatterns` list routes URLs to views. For more information please see:
4 + https://docs.djangoproject.com/en/1.11/topics/http/urls/
5 +Examples:
6 +Function views
7 + 1. Add an import: from my_app import views
8 + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
9 +Class-based views
10 + 1. Add an import: from other_app.views import Home
11 + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
12 +Including another URLconf
13 + 1. Import the include() function: from django.conf.urls import url, include
14 + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
15 +"""
16 +import blog.views
17 +from django.contrib import admin
18 +from django.conf import settings
19 +from django.conf.urls.static import static
20 +from django.conf.urls import include, url
21 +urlpatterns = [
22 + url(r'^admin/', admin.site.urls),
23 + # url('',views.home, name='home'),
24 + url('login/', blog.views.login, name='login'),
25 + url('logout/', blog.views.logout, name='logout'),
26 + url('register/', blog.views.register, name='register'),
27 +]+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
No preview for this file type
No preview for this file type
1 +"""
2 +WSGI config for khuloud project.
3 +
4 +It exposes the WSGI callable as a module-level variable named ``application``.
5 +
6 +For more information on this file, see
7 +https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
8 +"""
9 +
10 +import os
11 +
12 +from django.core.wsgi import get_wsgi_application
13 +
14 +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "khuloud.settings")
15 +
16 +application = get_wsgi_application()
No preview for this file type
No preview for this file type
1 +# -*- coding: utf-8 -*-
2 +from __future__ import unicode_literals
3 +
4 +from django.contrib import admin
5 +
6 +# Register your models here.
No preview for this file type
1 +# -*- coding: utf-8 -*-
2 +from __future__ import unicode_literals
3 +
4 +from django.apps import AppConfig
5 +
6 +
7 +class LoginConfig(AppConfig):
8 + name = 'login'
No preview for this file type
1 +# -*- coding: utf-8 -*-
2 +from __future__ import unicode_literals
3 +
4 +from django.db import models
5 +
6 +# Create your models here.
No preview for this file type
1 +# -*- coding: utf-8 -*-
2 +from __future__ import unicode_literals
3 +
4 +from django.test import TestCase
5 +
6 +# Create your tests here.
1 +from django.shortcuts import render,redirect
2 +from django.contrib.auth.models import User
3 +from django.contrib import auth
4 +
5 +
6 +def signup(request):
7 + if request.method=="POST":
8 + if request.POST["password1"]==request.POST["password2"]:
9 + user=User.objects.create_user(
10 + username1=request.POST["username"],
11 + password=request.POST["password1"]
12 + )
13 + auth.login(request,user)
14 + return redirect('login')
15 + return render(request,'signup.html')
16 + return render(request,'signup.html')
17 +def login(request):
18 + if request.method=="POST":
19 + username=request.POST['username']
20 + password=request.POST['password']
21 + user=auth.authenticate(request,username=username,password=password)
22 + if user is not None:
23 + auth.login(request,user)
24 + return redirect('home')
25 + else:
26 + return render(request,'login.html',{'error':'error!'})
27 + else:
28 + return render(request,'login.html')
29 +
30 +def logout(request):
31 + auth.logout(request)
32 + return redirect('home')
...\ No newline at end of file ...\ No newline at end of file
No preview for this file type
1 +#!/usr/bin/env python
2 +import os
3 +import sys
4 +
5 +if __name__ == "__main__":
6 + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "khuloud.settings")
7 + try:
8 + from django.core.management import execute_from_command_line
9 + except ImportError:
10 + # The above import may fail for some other reason. Ensure that the
11 + # issue is really that Django is missing to avoid masking other
12 + # exceptions on Python 2.
13 + try:
14 + import django
15 + except ImportError:
16 + raise ImportError(
17 + "Couldn't import Django. Are you sure it's installed and "
18 + "available on your PYTHONPATH environment variable? Did you "
19 + "forget to activate a virtual environment?"
20 + )
21 + raise
22 + execute_from_command_line(sys.argv)
1 +import boto3
2 +
3 +
4 +
5 +# Get the service resource.
6 +
7 +dynamodb = boto3.resource('dynamodb')
8 +
9 +
10 +
11 +# Create the DynamoDB table.
12 +
13 +table = dynamodb.create_table(
14 +
15 + TableName='users',
16 +
17 + KeySchema=[
18 +
19 + {
20 +
21 + 'AttributeName': 'username',
22 +
23 + 'KeyType': 'HASH'
24 +
25 + },
26 +
27 + {
28 +
29 + 'AttributeName': 'last_name',
30 +
31 + 'KeyType': 'RANGE'
32 +
33 + }
34 +
35 + ],
36 +
37 + AttributeDefinitions=[
38 +
39 + {
40 +
41 + 'AttributeName': 'username',
42 +
43 + 'AttributeType': 'S'
44 +
45 + },
46 +
47 + {
48 +
49 + 'AttributeName': 'last_name',
50 +
51 + 'AttributeType': 'S'
52 +
53 + },
54 +
55 +
56 +
57 + ],
58 +
59 + ProvisionedThroughput={
60 +
61 + 'ReadCapacityUnits': 5,
62 +
63 + 'WriteCapacityUnits': 5
64 +
65 + }
66 +
67 +)
68 +
69 +
70 +
71 +# Wait until the table exists.
72 +
73 +table.meta.client.get_waiter('table_exists').wait(TableName='users')
74 +
75 +
76 +
77 +# Print out some data about the table.
78 +
79 +print(table.item_count)
80 +
81 +