-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimplePaymentAuth.sol
More file actions
110 lines (90 loc) · 2.97 KB
/
Copy pathSimplePaymentAuth.sol
File metadata and controls
110 lines (90 loc) · 2.97 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
pragma solidity ^0.4.2;
//@notice : blind auction contract
//@warning : this is not to be used in production
//@info: SimplePaymentAuth is a smart contract for managing subscription based
// logins to any authorization system
// Since we are simply storing hashes
import "./safeMath.sol";
contract FixedAmountSimplePaymentAuth {
address public owner;
bytes32 public siteName;
bytes32 public feeCycle;
uint256 public feeAmount;
bool public ended;
struct User {
address loginUsername;
bytes32 passHash;
uint lastPaymentDate;
}
mapping(address => User) private users;
mapping(address => uint256) private refunds;
event NewUser(address userAddress, bytes32 passHash, uint256 timeStamp);
event RenewedSubscription(address userAddress, uint256 timeStamp);
event Ended(bool ended);
event FeeChanged(uint256 newFee);
event PasswordChanged(address userAddress, bytes32 passHash);
modifier onlyOwner() {
assert(msg.sender == owner);
_;
}
modifier notEnded() {
assert(!ended);
_;
}
modifier sufficientFee() {
assert(msg.value >= feeAmount);
_;
}
modifier onlyNewUser() {
assert(users[msg.sender].loginUsername == 0);
_;
}
modifier onlyExistingUser() {
assert(users[msg.sender].loginUsername != 0);
_;
}
function FixedAmountSimplePaymentAuth(uint256 feeAmt, bytes32 cycle, bytes32 name ) public {
owner = msg.sender;
feeAmount = feeAmt;
siteName = name;
feeCycle = cycle;
}
/**
* @dev payable fallback
*/
function () public payable {}
function signUp(bytes32 passHash) public payable notEnded onlyNewUser sufficientFee {
uint256 extraAmount = SafeMath.sub(msg.value, feeAmount);
users[msg.sender] = User({
loginUsername: msg.sender,
passHash: passHash,
lastPaymentDate: block.timestamp
});
refunds[msg.sender] = extraAmount;
NewUser(msg.sender, passHash, now);
}
function renewSubscription() public payable notEnded onlyExistingUser sufficientFee {
uint256 extraAmount = SafeMath.sub(msg.value, feeAmount);
refunds[msg.sender] += extraAmount;
users[msg.sender].lastPaymentDate = now;
RenewedSubscription(msg.sender, now);
}
function withdrawRefund() public onlyExistingUser {
assert(refunds[msg.sender] > 0);
uint256 amt = refunds[msg.sender];
refunds[msg.sender] = 0;
msg.sender.transfer(amt);
}
function changePassword(bytes32 newPas) public notEnded onlyExistingUser {
users[msg.sender].passHash = newPas;
PasswordChanged(msg.sender, newPas);
}
function kill() public notEnded onlyOwner {
ended = true;
Ended(true);
}
function withdraw(uint256 amount, address to) public onlyOwner {
assert(amount <= this.balance);
to.transfer(amount);
}
}