Fakultas Ilmu Komputer UI

Commit 635cad5c authored by zakiraihan's avatar zakiraihan
Browse files

add phone number confirmation

parent c9c4e8a8
......@@ -72,20 +72,6 @@ def auth():
return (jsonify(), 400)
@app.route("/auth/", methods=['GET'])
def authGet():
ticket = request.args.get('ticket')
print(ticket)
service_url = "https://56e25c7f.ngrok.io/auth/"
if (ticket is not None) and (service_url is not None):
client = get_cas_client(service_url)
sso_profile = authenticate(ticket, client)
if sso_profile is not None:
user_data = sso_profile
print(sso_profile)
return (jsonify(user_data), 200)
return "AHOYYYY"
@app.route('/loginsso', methods=['GET'])
def renderLoginSSOPage():
return render_template('loginSSO.html')
......@@ -100,10 +86,33 @@ def getLoginSSOData():
access_token = None
if (access_token != None):
return render_template('authPhoneNumber.html', username=username)
return redirect(url_for('.renderSetPhoneNumber', username=username))
else:
return "gagal :("
return redirect(url_for('.renderFailedToLoginSSO'))
@app.route('/loginsso/setPhoneNumber', methods=['GET'])
def renderSetPhoneNumber():
username = request.args.get('username')
return render_template('authPhoneNumber.html', username=username)
@app.route('/submitPhoneNumber', methods=['POST'])
def createSSOAccount():
from telebot.utils import create_user_sso_account
print(request.form)
username = request.form['username']
phoneNumber = request.form['phoneNumber']
# createdSSOAccountStatus = create_user_sso_account(username, phoneNumber)
createdSSOAccountStatus = "success"
if (createdSSOAccountStatus == "success"):
return render_template('successToLoginSSO.html', username=username)
elif (createdSSOAccountStatus == "failed"):
return "Failed, account has been created before"
else:
return "Error while creating account"
@app.route('/loginsso/failed', methods=['GET'])
def renderFailedToLoginSSO():
return render_template('failedToLoginSSO.html')
if __name__ == '__main__':
app.run(threaded=True)
\ No newline at end of file
"""empty message
Revision ID: 091749de5cb7
Revision ID: 6154c23d44d5
Revises: None
Create Date: 2019-09-26 19:19:15.875369
Create Date: 2019-10-04 13:34:49.589488
"""
# revision identifiers, used by Alembic.
revision = '091749de5cb7'
revision = '6154c23d44d5'
down_revision = None
from alembic import op
......@@ -16,6 +16,18 @@ import sqlalchemy as sa
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('account',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('chatId', sa.String(), nullable=True),
sa.Column('phoneNumber', sa.String(), nullable=False),
sa.Column('ssoId', sa.String(), nullable=False),
sa.Column('firstName', sa.String(), nullable=True),
sa.Column('lastName', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('chatId'),
sa.UniqueConstraint('phoneNumber'),
sa.UniqueConstraint('ssoId')
)
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('userId', sa.String(), nullable=False),
......@@ -32,4 +44,5 @@ def upgrade():
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('user')
op.drop_table('account')
# ### end Alembic commands ###
......@@ -12,12 +12,9 @@ class AccountModel(db.Model):
firstName = db.Column(db.String())
lastName = db.Column(db.String())
def __init__(self, chatId, phoneNumber, ssoId, firstName, lastName):
self.chatId = chatId
def __init__(self, phoneNumber, ssoId):
self.phoneNumber = phoneNumber
self.ssoId = ssoId
self.firstName = firstName
self.lastName = lastName
def save(self):
db.session.add(self)
......
......@@ -48,10 +48,7 @@ def user_deactive_notif(bot, chat_id):
def user_login_sso(bot, chat_id):
base_url = os.environ.get('URL')
sso_url = os.environ.get('SSO_UI_URL')
app_auth_url = "https://" + base_url + '/auth/'
URL = sso_url + "/login?service=" + app_auth_url
response = "Please login through this link:\n" + URL
response = "Please login through this link:\n" + base_url + "/loginsso"
bot.sendMessage(chat_id=chat_id, text=response)
def user_logout_sso(bot, chat_id):
......@@ -61,3 +58,18 @@ def user_logout_sso(bot, chat_id):
URL = sso_url + "/logout?url=" + app_auth_url
response = "Please logout through this link:\n" + URL
bot.sendMessage(chat_id=chat_id, text=response)
# def user_login_sso(bot, chat_id):
# base_url = os.environ.get('URL')
# sso_url = os.environ.get('SSO_UI_URL')
# app_auth_url = "https://" + base_url + '/auth/'
# URL = sso_url + "/login?service=" + app_auth_url
# response = "Please login through this link:\n" + URL
# bot.sendMessage(chat_id=chat_id, text=response)
# def user_logout_sso(bot, chat_id):
# base_url = os.environ.get('URL')
# sso_url = os.environ.get('SSO_UI_URL')
# app_auth_url = "https://" + base_url + '/auth/'
# URL = sso_url + "/logout?url=" + app_auth_url
# response = "Please logout through this link:\n" + URL
# bot.sendMessage(chat_id=chat_id, text=response)
import os
from models.UserModel import UserModel
from models.AccountModel import AccountModel
def create_user_sso_account(username, phoneNumber):
checkAccountExistance = AccountModel.query.filter(AccountModel.ssoId==str(username)).first()
try:
if (checkAccountExistance is None):
account = AccountModel(str(phoneNumber), str(username))
account.save()
return "success"
else:
return "failed"
except Exception as e:
return "error"
\ No newline at end of file
......@@ -9,30 +9,62 @@
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://sso.ui.ac.id/cas/themes/ui/sso.css" />
<link rel="icon" href="https://sso.ui.ac.id/cas/themes/ui/logo2_0.gif" type="image/x-icon" />
<style>
.makeSureBox {
width: 400px;
max-width: 400px;
display: inline-block;
border: 2px solid #000;
border-radius: 10px;
overflow: hidden;
}
.boxTitle {
padding-top: 15px;
color: white;
background-color: #5c94bd;
border-bottom: 2px solid #000;
}
.ssoContent {
padding-right: 23px;
padding-left: 23px;
}
.ssoBtn {
margin-bottom: 15px;
border-radius: 10px;
background-color: #5c94bd;
border-color: #5c94bd;
}
</style>
</head>
<body>
<div class="container d-flex align-items-center justify-content-center min-vh-100">
<div class="makeSureBox" style="border: 2px solid grey;">
<div class="row d-flex justify-content-center">
<h1>Fasilkom Telegram Bot Notification</h1>
<div class="makeSureBox">
<div class="row d-flex justify-content-center boxTitle" >
<h5 style="text-align:center;">Fasilkom Telegram Bot Notification</h5>
</div>
<div style='clear:both'></div>
<br>
<div class="row">
<p>
Username yang akan anda masukkan adalah: <br>
{{ username }}
<div class="row ssoContent">
<p style="text-align:justify;">
Untuk menghubungkan akun telegram dan sso diperlukan nomor telefon yang terdaftar pada telegram.
</p>
<p style="text-align:justify;">
Pastikan nomor telefon yang dimasukkan merupakan nomor yang digunakan pada akun telegram anda.
</p>
</div>
<div class="row">
<form class="phoneSubmit" action="/submitPhone" method="post">
<input id="username" name="username", type="hidden", value="{{ username }}">
<div class="row ssoContent d-flex justify-content-center align-items-center">
<form class="phoneSubmit" action="/submitPhoneNumber" method="post">
<div class="form-group">
<p>Untuk menghubungkan akun telegram dan sso diperlukan nomor telefon yang terdaftar pada telegram, silahkan masukkan</p>
<label for="username">Username SSO:</label>
<input id="username" name="username" class="form-control" type="text" value="{{ username }}" readonly/>
</div>
<div class="form-group">
<label for="phonenumber">Telegram Phone Number:</label>
<input id="phonenumber" name="phonenumber" class="form-control" placeholder="ex: 6281319053724" type="text" value=""/>
<label for="phoneNumber">Telegram Phone Number:</label>
<input id="phoneNumber" name="phoneNumber" class="form-control" placeholder="ex: 6281319053724" type="text" value=""/>
</div>
<div class="row d-flex justify-content-center align-items-center">
<button class="btn btn-primary ssoBtn" role="button" type="submit">Login SSO</button>
</div>
</form>
</div>
......@@ -46,3 +78,8 @@
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta content='width=device-width, initial-scale=1' name='viewport' />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Login Fasilkom Telegram Bot</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://sso.ui.ac.id/cas/themes/ui/sso.css" />
<link rel="icon" href="https://sso.ui.ac.id/cas/themes/ui/logo2_0.gif" type="image/x-icon" />
<style>
.makeSureBox {
width: 250px;
max-width: 250px;
display: inline-block;
border: 2px solid #000;
border-radius: 10px;
overflow: hidden;
}
.boxTitle {
padding-top: 15px;
color: white;
background-color: #5c94bd;
border-bottom: 2px solid #000;
}
.ssoMsg {
padding-right: 23px;
padding-left: 23px;
}
.ssoBtn {
margin-bottom: 15px;
border-radius: 10px;
}
</style>
</head>
<body>
<div class="container d-flex align-items-center justify-content-center min-vh-100">
<div class="makeSureBox">
<div class="row d-flex justify-content-center boxTitle" >
<h5 style="text-align:center;">Fasilkom Telegram Bot Notification</h5>
</div>
<div style='clear:both'></div>
<br>
<div class="row ssoMsg">
<p style="text-align:justify;">
Mohon maaf proses authentifikasi gagal dikarenakan kesalahan username atau password, silahkan coba kembali dengan menekan tombol dibawah ini.
</p>
</div>
<div class="row d-flex justify-content-center align-items-center">
<a href="/loginsso" class="btn btn-warning ssoBtn" role="button">Login SSO</a>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta content='width=device-width, initial-scale=1' name='viewport' />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Login Fasilkom Telegram Bot</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://sso.ui.ac.id/cas/themes/ui/sso.css" />
<link rel="icon" href="https://sso.ui.ac.id/cas/themes/ui/logo2_0.gif" type="image/x-icon" />
<style>
.makeSureBox {
width: 400px;
max-width: 400px;
display: inline-block;
border: 2px solid #000;
border-radius: 10px;
overflow: hidden;
}
.boxTitle {
padding-top: 15px;
color: white;
background-color: #5c94bd;
border-bottom: 2px solid #000;
}
.ssoContent {
padding-right: 23px;
padding-left: 23px;
}
.ssoBtn {
margin-bottom: 15px;
border-radius: 10px;
background-color: #5c94bd;
border-color: #5c94bd;
}
</style>
</head>
<body>
<div class="container d-flex align-items-center justify-content-center min-vh-100">
<div class="makeSureBox">
<div class="row d-flex justify-content-center boxTitle" >
<h5 style="text-align:center;">Fasilkom Telegram Bot Notification</h5>
</div>
<div style='clear:both'></div>
<br>
<div class="row ssoContent">
<p style="text-align:justify;">
Proses registrasi akun SSO berhasil untuk username: {{ username }}, silahkan aktifkan notifikasi melalui chat bot
</p>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment