Created
September 12, 2012 07:21
-
-
Save hozaka/3704928 to your computer and use it in GitHub Desktop.
for NeoCyon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Client side should check the activation status of current account. | |
# If not you should popup an input dialog for the user to enter their activation code. | |
# | |
# CLIENT SIDE CODE SAMPLE | |
def login(user_id, password) | |
user = User.validate_login_from_server(user_id, password) | |
if user.nil? | |
# provided user_id or password is incorrect. | |
# show an error message on client | |
show_message("invalide username or password") | |
else | |
if user.activated? == true | |
# user account is already activated | |
# show the character selector screen | |
show_character_selector_screen | |
else | |
# user account is not activated | |
# show a input dialog on client screen for the user to enter their activation code | |
show_activation_code_dialog("please enter your activation code") | |
end | |
end | |
end | |
# Server side should save the activation status of each account. | |
# If user's account is not activated and an activation code is provided, you should valid the activation code first and then update the status | |
# | |
# SERVER SIDE CODE SAMPLE | |
def login(user_id, password, activation_code = nil) | |
user = DB.User.validate_login(user_id, password) # validate the user id & password from database | |
if user.nil? | |
return false # invalid user_id or password, login failed and return the error message to client | |
else | |
if user.activated? == true | |
return true # user_id & password is matched, and account is already activated before, login succeed | |
else | |
# user account is not activated, you should check the activation code first | |
code = DB.ActivationCode.check(activation_code) | |
if code && code.used? == false | |
DB.start_transaction do | |
code.update_attribute(:used, true) | |
code.save | |
user.update_attribute(:activated, true) | |
user.save | |
end # update user's status and save to database, then login success | |
return true | |
else | |
return false | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment