From 324f14c719de2c1873c52748ccd191ce5158790c Mon Sep 17 00:00:00 2001 From: ilya Date: Tue, 12 Oct 2010 18:23:59 -0700 Subject: [PATCH] setting the token to nil on accept of invite --- app/models/user.rb | 5 +- config/locales/devise.en.yml | 46 --------------- config/locales/devise/devise.en.yml | 56 ++++++++++--------- .../invitations_controller_spec.rb | 25 +++++++++ 4 files changed, 59 insertions(+), 73 deletions(-) delete mode 100644 config/locales/devise.en.yml create mode 100644 spec/controllers/invitations_controller_spec.rb diff --git a/app/models/user.rb b/app/models/user.rb index 12322dca6..cb0604e91 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -266,8 +266,7 @@ class User end end - ###Helpers############ - + ###Invitations############ def accept_invitation!( opts = {} ) if self.invited? self.username = opts[:username] @@ -283,11 +282,13 @@ class User person_hash = opts.delete(:person) self.person = Person.create(person_hash) self.person.save + self.invitation_token = nil self.save self end end + ###Helpers############ def self.instantiate!( opts = {} ) opts[:person][:diaspora_handle] = "#{opts[:username]}@#{APP_CONFIG[:terse_pod_url]}" opts[:person][:url] = APP_CONFIG[:pod_url] diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml deleted file mode 100644 index 07a2611d0..000000000 --- a/config/locales/devise.en.yml +++ /dev/null @@ -1,46 +0,0 @@ -en: - errors: - messages: - not_found: "not found" - already_confirmed: "was already confirmed" - not_locked: "was not locked" - - devise: - failure: - unauthenticated: 'You need to sign in or sign up before continuing.' - unconfirmed: 'You have to confirm your account before continuing.' - locked: 'Your account is locked.' - invalid: 'Invalid email or password.' - invalid_token: 'Invalid authentication token.' - timeout: 'Your session expired, please sign in again to continue.' - inactive: 'Your account was not activated yet.' - sessions: - signed_in: 'Signed in successfully.' - signed_out: 'Signed out successfully.' - passwords: - send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.' - updated: 'Your password was changed successfully. You are now signed in.' - confirmations: - send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.' - confirmed: 'Your account was successfully confirmed. You are now signed in.' - registrations: - signed_up: 'You have signed up successfully. If enabled, a confirmation was sent to your e-mail.' - updated: 'You updated your account successfully.' - destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.' - unlocks: - send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.' - unlocked: 'Your account was successfully unlocked. You are now signed in.' - invitations: - send_instructions: 'Your invitation has been sent.' - invitation_token_invalid: 'The invitation token provided is not valid!' - updated: 'Your password was set successfully. You are now signed in.' - mailer: - confirmation_instructions: - subject: 'Confirmation instructions' - reset_password_instructions: - subject: 'Reset password instructions' - unlock_instructions: - subject: 'Unlock Instructions' - invitation: - subject: 'A friend wants you to join Diaspora!' - diff --git a/config/locales/devise/devise.en.yml b/config/locales/devise/devise.en.yml index 06308488b..07a2611d0 100644 --- a/config/locales/devise/devise.en.yml +++ b/config/locales/devise/devise.en.yml @@ -1,7 +1,3 @@ -# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - en: errors: messages: @@ -11,30 +7,40 @@ en: devise: failure: - unauthenticated: "You need to sign in or sign up before continuing." - unconfirmed: "You have to confirm your account before continuing." - locked: "Your account is locked." - invalid: "Invalid email or password." - invalid_token: "Invalid authentication token." - timeout: "Your session expired, please sign in again to continue." - inactive: "Your account was not activated yet." + unauthenticated: 'You need to sign in or sign up before continuing.' + unconfirmed: 'You have to confirm your account before continuing.' + locked: 'Your account is locked.' + invalid: 'Invalid email or password.' + invalid_token: 'Invalid authentication token.' + timeout: 'Your session expired, please sign in again to continue.' + inactive: 'Your account was not activated yet.' sessions: - signed_in: "Signed in successfully." - signed_out: "Signed out successfully." + signed_in: 'Signed in successfully.' + signed_out: 'Signed out successfully.' passwords: - send_instructions: "You will receive an email with instructions about how to reset your password in a few minutes." - updated: "Your password was changed successfully. You are now signed in." + send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.' + updated: 'Your password was changed successfully. You are now signed in.' confirmations: - send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes." - confirmed: "Your account was successfully confirmed. You are now signed in." + send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.' + confirmed: 'Your account was successfully confirmed. You are now signed in.' registrations: - signed_up: "You have signed up successfully. If enabled, a confirmation was sent to your e-mail." - updated: "You updated your account successfully." - destroyed: "Bye! Your account was successfully cancelled. We hope to see you again soon." + signed_up: 'You have signed up successfully. If enabled, a confirmation was sent to your e-mail.' + updated: 'You updated your account successfully.' + destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.' unlocks: - send_instructions: "You will receive an email with instructions about how to unlock your account in a few minutes." - unlocked: "Your account was successfully unlocked. You are now signed in." + send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.' + unlocked: 'Your account was successfully unlocked. You are now signed in.' + invitations: + send_instructions: 'Your invitation has been sent.' + invitation_token_invalid: 'The invitation token provided is not valid!' + updated: 'Your password was set successfully. You are now signed in.' mailer: - confirmation_instructions: "Confirmation instructions" - reset_password_instructions: "Reset password instructions" - unlock_instructions: "Unlock Instructions" + confirmation_instructions: + subject: 'Confirmation instructions' + reset_password_instructions: + subject: 'Reset password instructions' + unlock_instructions: + subject: 'Unlock Instructions' + invitation: + subject: 'A friend wants you to join Diaspora!' + diff --git a/spec/controllers/invitations_controller_spec.rb b/spec/controllers/invitations_controller_spec.rb new file mode 100644 index 000000000..ff87b4bcc --- /dev/null +++ b/spec/controllers/invitations_controller_spec.rb @@ -0,0 +1,25 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require 'spec_helper' + +describe InvitationsController do + render_views + let(:user) {Factory.create :user} + + before do + sign_in :user, user + end + + context 'inviting another user' do + it 'should create an invited user and add keep track of an invitor' do + debugger + params = {"user" => {"email" => "test@example.com"}} + post :create, params + #invitee = inviter.invite_user(:email => "test@example.com") + #invitee.inviters.includes?(inviter).should be true + end + end + +end