Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent duplicate registrations and add input validation #60

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions contracts/event_registration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ contract EventRegistration {
mapping(address => Participant) public participants;
address[] public participantAddresses;

event ParticipantRegistered(
address indexed participantAddress,
string fullname,
string eventName
);
event ParticipantUpdated(
address indexed participantAddress,
string fullname,
string eventName
);

function registerParticipant(
string memory _fullname,
string memory _stream,
Expand All @@ -22,16 +33,28 @@ contract EventRegistration {
string memory _phno,
string memory _roll
) public {
Participant memory newParticipant = Participant({
require(bytes(_fullname).length > 0, "Full name is required.");
require(bytes(_stream).length > 0, "Stream is required.");
require(bytes(_eventName).length > 0, "Event name is required.");
require(bytes(_email).length > 0, "Email is required.");
require(bytes(_phno).length > 0, "Phone number is required.");
require(bytes(_roll).length > 0, "Roll number is required.");

if (bytes(participants[msg.sender].fullname).length == 0) {
participantAddresses.push(msg.sender);
emit ParticipantRegistered(msg.sender, _fullname, _eventName);
} else {
emit ParticipantUpdated(msg.sender, _fullname, _eventName);
}

participants[msg.sender] = Participant({
fullname: _fullname,
stream: _stream,
eventName: _eventName,
email: _email,
phno: _phno,
roll: _roll
});
participants[msg.sender] = newParticipant;
participantAddresses.push(msg.sender);
}

function getParticipant(address _addr)
Expand Down