forked from HuijunXu/CUMT-Daily
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.cpp
68 lines (56 loc) · 1.16 KB
/
User.cpp
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
#include "User.h"
#include <QCryptographicHash>
#include <QDebug>
#include <QtSql/QtSql>
User::User()
{
}
User::~User()
{
}
QString User::uid()
{
return _uid;
}
QString User::userIcon()
{
return _userIcon;
}
QString User::nicName()
{
return _nicName;
}
bool User::loginState()
{
return _loginState;
}
bool User::userLogin(QString user, QString password)
{
QString md5;
QByteArray bb;
bb = QCryptographicHash::hash ( password.toLocal8Bit(), QCryptographicHash::Md5 );
md5.append(bb.toHex());
QString sql="select * from user where account='"+user+"' and password='"+md5+"'";
QSqlQuery query;
query.exec(sql);
qDebug()<<sql;
while (query.next())
{
_uid= query.value("uid").toString();
_nicName=query.value("nicname").toString();
_userIcon=QString(HOME)+"/timeline/pic/"+query.value("usericon").toString();
_loginState=true;
emit uidChanged();
emit nicNameChanged();
emit userIconChanged();
emit loginStateChanged();
return true;
}
return false;
}
bool User::logOff()
{
_loginState=false;
emit loginStateChanged();
return true;
}