Exemplo n.º 1
0
def set_values(mobile_no):
    sql = ("select * from register_g15 where "
           "mobile= %(mobile_no)s")
    bind = {
        "mobile_no":mobile_no,
    }
    try:
        con=DbConnectivity.create_connection()
        cur = con.cursor()
        cur.execute(sql,bind)
        r=cur.fetchone()
        usr=user.user()
        usr.set_mobile_no(r[0])
        usr.set_password(r[1])
        usr.set_recent_password(r[2])
        usr.set_dob(r[3])
        usr.set_dis_name(r[4])
        usr.set_sec_qn(r[5])
        usr.set_sec_ans(r[6])
        usr.set_last_login(r[7])
        usr.set_login(r[8])
        usr.set_attempts(r[9])
        return usr

    except DatabaseError as e:
        print(e)
    finally:
        cur.close()
        con.commit()
        con.close()
Exemplo n.º 2
0
def registration(mobile_no, password,date_of_birth,dis_name,sec_qn,sec_ans):
    query = ("Insert into REGISTER_G15"
             "(mobile,password,recent_password,dob,name,security_que,security_ans)"
             "VALUES(%(mobile)s,%(password)s,%(recent_password)s,%(dob)s,%(name)s,%(security_que)s,%(security_ans)s)")


    args = (mobile_no, password, password, date_of_birth, dis_name, sec_qn, sec_ans)
    data = {
    'mobile': mobile_no,
    'password': password,
    'recent_password': password,
    'dob': date_of_birth,
    'name': dis_name,
    'security_que': sec_qn,
    'security_ans': sec_ans,
    }
    try:

        con=DbConnectivity.create_connection()
        cur=con.cursor()
        cur.execute(query,data)
        con.commit()
        set_values.set_values(mobile_no)
        print("Registration Successful")
        return True
    except IntegrityError:
        raise MobileNumberAlreadyExists()
    except:
        raise InvalidDateException
    finally:
        cur.close()
        con.commit()
        con.close()
Exemplo n.º 3
0
def  get_messages(usr):
    try:
        mobile_no=str(usr.get_mobile_no())
        sender={}
        con=DbConnectivity.create_connection()
        cur = con.cursor()
        query=("select msg from msg_g15 where destid=%(mobile_no)s or source=%(mobile_no)s")
        bind={
            "mobile_no":str(mobile_no),
        }
        cur.execute(query,bind)
        #cur.execute("select * from msg_g15 where destid='"+str(mobile_no)+"' or source='"+str(mobile_no)+
        r=cur.fetchall()
        sender1=r
        #for row in r:
         #   if(str(row[0])!=str(mobile_no)):
          #      '''FOR UNREAD'''
           #     if(row[4]=='U'):
            #        if(row[0] not in sender.keys()):
             #           sender[row[0]]=1
              #      else:
               #         sender[row[0]]=sender[row[0]]+1
                #        '''READ RESET THE VALUE PART OF SENDER'''
                #else:
                 #   sender[row[0]]=0
            #else:
             #   if(row[1] not in sender.keys()):
              #      sender[row[1]]=0
        return sender1
    finally:
        cur.close()
        con.commit()
        con.close()
Exemplo n.º 4
0
def insert_msg(source,destination,msg):
    query = ("insert into msg_g15"
             "(source,destid,msg)"
             "values(%(source)s,%(destination)s,%(msg)s)")


    bind = {
    "source": source,
    "destination": destination,
    "msg": msg,
    }
    try:
        con=DbConnectivity.create_connection()
        cur = con.cursor()

        cur.execute(query,bind)
        con.commit()


        #cur.execute("insert into msg_g15 (source,destid,msg) values('"+str(source)+"','"+str(destination)+"','"+msg+"')")
    except errorcode as e:
        print("Error in insert msg")
        print(e)
    finally:
        cur.close()
        con.commit()
        con.close()
Exemplo n.º 5
0
def update_login(mobile_no):
    try:
        con=DbConnectivity.create_connection()
        cur = con.cursor()
        sql=("Update Register_G15 set last_login=systimestamp,login='******' where mobile= %(mobile_no)s")
        bind={"mobile_no":mobile_no}
        cur.execute(sql,bind)
    finally:
        cur.close()
        con.commit()
        con.close()
Exemplo n.º 6
0
def check_destination(mobile_no):
    con=DbConnectivity.create_connection()
    cur = con.cursor()
    query=("select mobile,name from register_g15 where mobile=%(mobile_no)s")
    bind={
        "mobile_no":str(mobile_no,)
    }
    cur.execute(query,bind)
    r = cur.fetchone()
    msg=messages.messages()
    msg.set_destinaton(r[0])
    msg.set_dis_name(r[1])
    return msg
Exemplo n.º 7
0
def update_msg_status(usr,destination):
    try:
        con=DbConnectivity.create_connection()
        cur = con.cursor()
        source=usr.get_mobile_no()
        bind={
            "destination":str(destination),
            "source":str(source),
        }
        query=("update msg_g15 set status='R' where source=%(destination)s and destid=%(source)s")
        cur.execute(query,bind)
        #cur.execute("update msg_g15 set status='R' where source='"+str(destination)+"' and destid='"+str(source)+"'")
    except DatabaseError as e:
        print("Error in Status Update")
        print(e)
    finally:
        cur.close()
        con.commit()
        con.close()
Exemplo n.º 8
0
def set_password(password,recent_password,mobile_no):
    try:
        con=DbConnectivity.create_connection()
        cur = con.cursor()
        query=("Update Register_G15 set password=%(password)s,recent_password=%(recent_password)s where "
              "mobile=%(mobile_no)s")
        bind={
            "password":password,
            "recent_password":recent_password,
            "mobile_no":mobile_no,
        }
        cur.execute(query,bind)

    except DatabaseError as e:
        print("Error in Status Update")
        print(e)
    finally:
        cur.close()
        con.commit()
        con.close()
Exemplo n.º 9
0
def print_messages(usr,chat_no):
    try:
        con=DbConnectivity.create_connection()
        cur = con.cursor()
        login_id=str(usr.get_mobile_no())
        query=("select msg,source,destid from msg_g15 where source in"
             "(%(login_id)s,%(chat_no)s) and destid in (%(login_id)s,%(chat_no)s) order by msgtime")
        bind={
            "login_id":str(login_id),
            "chat_no":str(chat_no),
        }
        cur.execute(query,bind)
        r=cur.fetchall()
        #cur.execute("select msg,source,destid,to_char(msgtime),abs(to_date(sysdate)-to_date(to_char(substr(msgtime,1,9)),'dd-mon-yy')), \
         #    to_char(to_date(to_char(substr(msgtime,1,9)),'dd-mon-yy'),'Dy') from msg_g15 where source in ('"+str(login_id)+"','"+str(chat_no)+"') and destid in ('"+str(login_id)+"','"+str(chat_no)+"') order by msgtime")
        print (r)


    finally:
        cur.close()
        con.commit()
        con.close()
Exemplo n.º 10
0
def print_unread_messages(usr,chat_no):
    try:
        con=DbConnectivity.create_connection()
        cur = con.cursor()
        login_id = str(usr.get_mobile_no())
        query=("select msg,source,destid from msg_g15 where source= %(chat_no)s"
              "and destid=%(login_id)s and status='U' order by msgtime")
        bind={
            "login_id":login_id,
            "chat_no":chat_no,
        }
        cur.execute(query,bind)
        #cur.execute("select msg,source,destid from msg_g15 where source="+chat_no+" and destid="+login_id+" and status='U' order by msgtime")
        for msg,source,destid in cur:
            if(source==login_id):
                dis_name='Me'
            else:
                dis_name=usr.get_dis_name()
            print(dis_name,"->",msg)
    finally:
        cur.close()
        con.commit()
        con.close()