forked from pranjalisood98/Online_Quiz_Portal
/
ums.py
77 lines (66 loc) · 2.15 KB
/
ums.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 18 14:50:19 2019
"""
from tools import query, connect
class ums:
def __init__(self, server):
self.server = server
self.username = None
self.curr_dept = None
self.curr_sub = None
def retrive_user_details(self):
# cursor.execute("Use admin;")
cursor = query(self.server,"Use admin;")
# cursor.execute("select department_id, subject_id from users where username = '" + self.username + "';")
cursor = query(self.server,"select department_id, subject_id from users where username = '" + self.username + "';")
rec = cursor.fetchall()
self.curr_dept = rec[0][0]
self.curr_sub = rec[0][1]
def register(self, username, password, dept, sub, admin=True):
if self.curr_dept == None or self.curr_sub == None:
return False
val = (username, password, dept, sub)
if admin:
# cursor.execute("USE admin;")
cursor = query(self.server,"USE admin;")
else:
# cursor.execute("USE student;")
cursor = query(self.server,"USE student;")
sql = "select username from users where username= '" + username + "';"
cursor = query(self.server,sql)
rec = cursor.fetchall()
if len(rec) != 0:
return False
sql = "INSERT INTO users (username, password, department_id, subject_id) VALUES (%s, %s, %s, %s)"
cursor = query(self.server,sql, val)
self.server.commit()
return True
def login(self, username, password, admin=True):
# val = (username, password)
if admin:
# cursor.execute("USE admin;")
cursor = query(self.server,"USE admin;")
else:
# cursor.execute("USE student;")
cursor = query(self.server,"USE student;")
sql = "select password from users where username= '" + username + "';"
cursor = query(self.server,sql)
rec = cursor.fetchall()
if len(rec) == 0:
return False
if rec[0][0] == password:
return True
else:
return False
#import mysql.connector
#
#server = mysql.connector.connect(
# host="localhost",
# user="root",
# passwd="Naman@123"
#)
#
#ums_obj = ums(server)
#check = ums_obj.register("naman","Naman@123", admin=False)
#print(check)