Fakultas Ilmu Komputer UI

utils.py 1.54 KB
Newer Older
zakiraihan's avatar
zakiraihan committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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:
15
16
17
18
        return "error"

def check_if_user_exist(username):
    checkAccountExistance = AccountModel.query.filter(AccountModel.ssoId==str(username)).first()
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
    return checkAccountExistance != None

def logoutSSOUser(username):
    checkAccountExistance = AccountModel.query.filter(AccountModel.ssoId==str(username)).first()
    try:
        checkAccountExistance.delete()
        return "success"
        
    except Exception as e:
        return "error"

def getAccountCurrentPhoneNumber(username):
    checkAccountExistance = AccountModel.query.filter(AccountModel.ssoId==str(username)).first()
    try:
        return checkAccountExistance.phoneNumber
    except Exception as e:
        return "error"

def changeAccountPhoneNumber(username, newPhoneNumber):
    checkAccountExistance = AccountModel.query.filter(AccountModel.ssoId==str(username)).first()
    try:
        checkAccountExistance.phoneNumber = newPhoneNumber
41
        checkAccountExistance.chatId = None
42
43
44
45
        checkAccountExistance.update()
        return "success"
    except Exception as e:
        return "error"