Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
OnlyOneJMJQ committed Nov 1, 2017
2 parents f55e069 + e179465 commit 78a3f5d
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 75 deletions.
47 changes: 24 additions & 23 deletions contracts/Authentication.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,34 @@ contract Authentication is Killable {

uint private id; // Stores user id temporarily

function login() constant returns (bytes32) {
// Check if user exists.
// If yes, return user.
// If no, throw.
modifier onlyExistingUser {
// Check if user exists or terminate

if (users[msg.sender].name == 0x0)
{
throw;
}
require(!(users[msg.sender].name == 0x0));
_;
}

modifier onlyValidName(bytes32 name) {
// Only valid names allowed

require(!(name == 0x0));
_;
}

function login() constant
onlyExistingUser
returns (bytes32) {
return (users[msg.sender].name);
}

function signup(bytes32 name) payable returns (bytes32) {
function signup(bytes32 name)
payable
onlyValidName(name)
returns (bytes32) {
// Check if user exists.
// If yes, return user name.
// If no, check if name was sent.
// If yes, create and return user.
// If no, throw.

if (name == 0x0)
{
throw;
}

if (users[msg.sender].name == 0x0)
{
Expand All @@ -46,21 +50,18 @@ contract Authentication is Killable {
return (users[msg.sender].name);
}

function update(bytes32 name) payable returns (bytes32) {
function update(bytes32 name)
payable
onlyValidName(name)
onlyExistingUser
returns (bytes32) {
// Update user name.

if (name == 0x0)
{
throw;
}

if (users[msg.sender].name != 0x0)
{
users[msg.sender].name = name;

return (users[msg.sender].name);
}

throw;
}
}
13 changes: 0 additions & 13 deletions contracts/SimpleStorage.sol

This file was deleted.

2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ class App extends Component {
return (
<div className="App">
<nav className="navbar pure-menu pure-menu-horizontal">
<Link to="/" className="pure-menu-heading pure-menu-link">Truffle Box</Link>
<ul className="pure-menu-list navbar-right">
<OnlyGuestLinks />
<OnlyAuthLinks />
</ul>
<Link to="/" className="pure-menu-heading pure-menu-link">Truffle Box</Link>
</nav>

{this.props.children}
Expand Down
2 changes: 0 additions & 2 deletions src/user/ui/signupform/SignUpFormContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ const mapStateToProps = (state, ownProps) => {
const mapDispatchToProps = (dispatch) => {
return {
onSignUpFormSubmit: (name) => {
event.preventDefault();

dispatch(signUpUser(name))
}
}
Expand Down
19 changes: 19 additions & 0 deletions test/TestAuthentication.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
pragma solidity ^0.4.2;

import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/Authentication.sol";

contract TestAuthentication {

function testUserCanSignUpAndLogin() {
Authentication authentication = Authentication(DeployedAddresses.Authentication());

authentication.signup('testuser');

bytes32 expected = 'testuser';

Assert.equal(authentication.login(), expected, "It should sign up and log in a user.");
}

}
19 changes: 0 additions & 19 deletions test/TestSimpleStorage.sol

This file was deleted.

17 changes: 17 additions & 0 deletions test/authentication.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var Authentication = artifacts.require("./Authentication.sol");

contract('Authentication', function(accounts) {

it("...should sign up and log in a user.", function() {
return Authentication.deployed().then(function(instance) {
authenticationInstance = instance;

return authenticationInstance.signup('testuser', {from: accounts[0]});
}).then(function() {
return authenticationInstance.login.call();
}).then(function(userName) {
assert.equal(web3.toUtf8(userName), 'testuser', "The user was not signed up.");
});
});

});
17 changes: 0 additions & 17 deletions test/simplestorage.js

This file was deleted.

0 comments on commit 78a3f5d

Please sign in to comment.