forked from activefx/restful_authentication_tutorial
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
beginnings of a beta invitation system in place
- Loading branch information
activefx
committed
Sep 12, 2008
1 parent
a2150a0
commit d15de95
Showing
28 changed files
with
272 additions
and
48 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class User::InvitationsController < ApplicationController | ||
|
||
def new | ||
@invitation = Invitation.new | ||
end | ||
|
||
def create | ||
@invitation = Invitation.new(params[:invitation]) | ||
@invitation.sender = current_user | ||
if @invitation.save | ||
if logged_in? | ||
UserMailer.deliver_invitation(@invitation) | ||
flash[:notice] = "Thank you, invitation sent." | ||
redirect_to root_path | ||
else | ||
flash[:notice] = "Thank you, we will notify you when an invitation becomes available." | ||
redirect_to root_path | ||
end | ||
else | ||
render :action => 'new' | ||
end | ||
end | ||
|
||
end | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class Invitation < ActiveRecord::Base | ||
belongs_to :sender, :class_name => 'User' | ||
has_one :recipient, :class_name => 'User' | ||
|
||
validates_presence_of :email | ||
validate :recipient_is_not_registered | ||
validate :sender_has_invitations, :if => :sender | ||
|
||
before_create :generate_token | ||
before_create :decrement_sender_count, :if => :sender | ||
|
||
attr_accessible :email | ||
|
||
private | ||
|
||
def recipient_is_not_registered | ||
errors.add :email, 'is already registered' if User.find_by_email(email) | ||
end | ||
|
||
def sender_has_invitations | ||
unless sender.invitation_limit > 0 | ||
errors.add_to_base 'You have reached your limit of invitations to send.' | ||
end | ||
end | ||
|
||
def generate_token | ||
self.token = User.make_token #Digest::SHA1.hexdigest([Time.now, rand].join) | ||
end | ||
|
||
def decrement_sender_count | ||
sender.decrement! :invitation_limit | ||
end | ||
|
||
end |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
class UserObserver < ActiveRecord::Observer | ||
def after_create(user) | ||
UserMailer.deliver_signup_notification(user) | ||
end | ||
|
||
#def after_create(user) | ||
#end | ||
|
||
def after_save(user) | ||
UserMailer.deliver_activation(user) if user.recently_activated? | ||
UserMailer.deliver_forgot_password(user) if user.recently_forgot_password? | ||
UserMailer.deliver_reset_password(user) if user.recently_reset_password? | ||
UserMailer.deliver_signup_notification(user) if user.lost_activation_code? | ||
end | ||
|
||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<h1>Sign up with OpenID</h1> | ||
|
||
<% form_tag session_path do -%> | ||
<%= hidden_field_tag 'openid', true %> | ||
<% if_in_beta? do -%> | ||
<p><%= label_tag 'invitation_token', 'Invitation Code' %><br/> | ||
<%= text_field_tag :invitation_token, params[:invitation_token] %> | ||
<span>*we are currently in private beta and an invitation code is required</span></p> | ||
<% end -%> | ||
|
||
<p><%= label_tag 'openid_indentifier', 'OpenID Url' %><br/> | ||
<%= text_field_tag "openid_identifier", @openid_identifier %></p> | ||
|
||
<% if_recaptcha? do %> | ||
<p>Please enter the following words below.<br/> | ||
<%= recaptcha_tags %></p> | ||
<% end %> | ||
|
||
<p><%= submit_tag 'Log in', :disable_with => "Signing in…" %></p> | ||
<% end -%> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
<% content_for :side do -%> | ||
<% unless logged_in? -%><% if_in_beta? do -%> | ||
<p>We are currently in private beta. Please enter your email address below and we will let know when an invitation becomes available.</p> | ||
<% uberform_for [:user, Invitation.new] do |f| -%> | ||
<%= f.text_field :email, :label => "Your Email:" %> | ||
<%= f.submit 'Submit' %> | ||
<% end -%> | ||
<% end -%><% end -%> | ||
<% end -%> | ||
|
||
<h1>Welcome to my application.</h1> | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<h1>Send invitation</h1> | ||
|
||
<%= error_messages_for :invitation %> | ||
<% uberform_for [:user, @invitation] do |f| %> | ||
<%= f.text_field :email, :label => "Friend's email address:" %> | ||
<%= f.submit "Invite!" %> | ||
<% end %> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
<h1>Sign up as a new user</h1> | ||
<h1>Sign up as a new OpenID user</h1> | ||
|
||
<%= error_messages_for :user %> | ||
<% form_for :user, :url => user_openid_accounts_path do |f| -%> | ||
<%= f.hidden_field :identity_url %> | ||
|
||
<p><label for="name">Name (optional)</label><br/> | ||
<%= f.text_field :name %></p> | ||
|
||
<p><label for="login">Username</label><br/> | ||
<%= f.text_field :login %></p> | ||
|
||
<p><label for="email">Email</label><br/> | ||
<%= f.text_field :email %></p> | ||
|
||
<p><%= submit_tag 'Sign up' %></p> | ||
<% form_for :user, :url => user_openid_accounts_path, :builder => Uberkit::Forms::Builder do |f| -%> | ||
<%= f.hidden_field :identity_url %> | ||
<%= f.hidden_field :invitation_token %> | ||
<%= f.text_field :name, :help => "*optional" %> | ||
<%= f.text_field :login, :label => "Username" %> | ||
<% if in_beta? -%> | ||
<%= f.text_field :email, | ||
:help => "*email should match the one your invitation code was sent to, or you will have to activate your account" %> | ||
<% else -%> | ||
<%= f.text_field :email %> | ||
<% end -%> | ||
<%= f.submit 'Sign up' %> | ||
<% end -%> | ||
<%= "#{@token}" %> |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
You have been invited to join our private beta! | ||
|
||
<%= @url %> | ||
|
Oops, something went wrong.