| 459 | | # pre-populate the session table and the realname/email table with user data |
|---|
| 460 | | try: |
|---|
| | 459 | # check if user is already in the sessions table |
|---|
| | 460 | c.execute("SELECT sid FROM session WHERE sid = '%s'" % result[0]['username'].encode('utf-8')) |
|---|
| | 461 | r = c.fetchall() |
|---|
| | 462 | |
|---|
| | 463 | # if there was no user sid in the database already |
|---|
| | 464 | if not r: |
|---|
| | 465 | # pre-populate the session table and the realname/email table with user data |
|---|
| | 466 | try: |
|---|
| | 467 | c.execute( |
|---|
| | 468 | """INSERT INTO session |
|---|
| | 469 | (sid, authenticated, last_visit) |
|---|
| | 470 | VALUES """,(result[0]['username'].encode('utf-8'), '1', result[0]['last_visit'].strftime('%s'))) |
|---|
| | 471 | except: |
|---|
| | 472 | print 'failed executing sql: ' |
|---|
| | 473 | print """INSERT INTO session |
|---|
| | 474 | (sid, authenticated, last_visit) |
|---|
| | 475 | VALUES """, (result[0]['username'].encode('utf-8'), '1', result[0]['last_visit'].strftime('%s')) |
|---|
| | 476 | print 'could not insert %s into sessions table: sql error %s ' % (loginName, self.db().error()) |
|---|
| | 477 | self.db().commit() |
|---|
| | 478 | |
|---|
| | 479 | # insert the user's real name into session attribute table |
|---|
| 462 | | """INSERT INTO session |
|---|
| 463 | | (sid, authenticated, last_visit) |
|---|
| 464 | | VALUES |
|---|
| 465 | | (%s, 1, %s)""",(result[0]['username'].encode('utf-8'), result[0]['last_visit'].strftime('%s'))) |
|---|
| 466 | | except: |
|---|
| 467 | | print 'could not insert %s into sessions table: sql error %s ' % loginName, self.db().error() |
|---|
| 468 | | self.db().commit() |
|---|
| 469 | | |
|---|
| 470 | | # insert the user's real name into session attribute table |
|---|
| 471 | | c.execute( |
|---|
| 472 | | """INSERT INTO session_attribute |
|---|
| 473 | | (sid, authenticated, name, value) |
|---|
| 474 | | VALUES |
|---|
| 475 | | (%s, %s, %s, %s)""", |
|---|
| 476 | | (result[0]['username'].encode('utf-8'), '1', 'name', result[0]['realname'].encode('utf-8'))) |
|---|
| 477 | | self.db().commit() |
|---|
| 478 | | |
|---|
| 479 | | # insert the user's email into session attribute table |
|---|
| 480 | | c.execute( |
|---|
| 481 | | """INSERT INTO session_attribute |
|---|
| 482 | | (sid, authenticated, name, value) |
|---|
| 483 | | VALUES |
|---|
| 484 | | (%s, %s, %s, %s)""", |
|---|
| 485 | | (result[0]['username'].encode('utf-8'), '1', 'email', result[0]['email'].encode('utf-8'))) |
|---|
| 486 | | self.db().commit() |
|---|
| | 481 | """INSERT INTO session_attribute |
|---|
| | 482 | (sid, authenticated, name, value) |
|---|
| | 483 | VALUES |
|---|
| | 484 | """, (result[0]['username'].encode('utf-8'), '1', 'name', result[0]['realname'].encode('utf-8'))) |
|---|
| | 485 | self.db().commit() |
|---|
| | 486 | |
|---|
| | 487 | # insert the user's email into session attribute table |
|---|
| | 488 | c.execute( |
|---|
| | 489 | """INSERT INTO session_attribute |
|---|
| | 490 | (sid, authenticated, name, value) |
|---|
| | 491 | VALUES |
|---|
| | 492 | """, (result[0]['username'].encode('utf-8'), '1', 'email', result[0]['email'].encode('utf-8'))) |
|---|
| | 493 | self.db().commit() |
|---|