-
Notifications
You must be signed in to change notification settings - Fork 19
/
contract.sol
94 lines (80 loc) · 2.8 KB
/
contract.sol
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
pragma solidity ^0.4.0;
contract Register{
struct Administrators{
address ownerAdr;
string ownerName;
bytes32 password;
}
address public owner;
uint AdministratorsNum = 0;
address[] addrList;
mapping(string=>bool) registerPool;
mapping(string => Administrators) userPool;
function Register() public {
owner = msg.sender;
}
//注册
function login(string username, string password) constant public returns (bool) {
return userPool[username].password == keccak256(password);
}
//注册检测
function checkRegister(address addr,string username) constant public returns (bool) {
for(uint i = 0; i < addrList.length; ++i){
if(addrList[i] == addr||registerPool[username]==true)
return true;
}
return false;
}
// 用户注册
function register(address addr, string username, string password) public {
require(!(msg.sender!=owner));
require(!checkRegister(addr,username));
userPool[username] = Administrators(addr, username, keccak256(password));
addrList.push(addr);
registerPool[username]=true;
++AdministratorsNum;
}
// 更新密码
function updatePassword(string username, string newPwd) public {
require(msg.sender != owner);
// keccak256加密
userPool[username].password = keccak256(newPwd);
}
function addMsg(string username,string ID,string violateRecord,uint lowPoint,string AdministratorName) public{
require(msg.sender!=owner) ;
AddorSearch addmsg = new AddorSearch();
addmsg.addMsg(username,ID,violateRecord,lowPoint, AdministratorName);
}
}
contract AddorSearch{
struct Msg{
string userName;
string ID;
string violateRecord;
uint lowPoint;
string AdministratorName;
}
Msg[] violateRecords;
uint totalMsg=0;
function addMsg(string username,string ID,string violateRecord,uint lowPoint,string AdministratorName ) public{
violateRecords.push(Msg(username,ID,violateRecord,lowPoint,AdministratorName));
}
function returnTotal() constant public returns (uint) {
return violateRecords.length;
}
function getuserName(uint id) constant public returns (string){
return violateRecords[id].userName;
}
function getID(uint id) constant public returns (string){
return violateRecords[id].ID;
}
function getviolateRecord(uint id) constant public returns (string){
return violateRecords[id].violateRecord;
}
function getlowPoint(uint id) constant public returns (uint){
return violateRecords[id].lowPoint;
}
function getAdministrator(uint id) constant public returns (string){
return violateRecords[id].AdministratorName;
}
}