Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
200 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
class RegistrationsController < ApplicationController | ||
|
||
skip_before_filter :login_required, :except => [:edit, :update] | ||
|
||
def new | ||
@user = User.new(:ucontact => Ucontact.new, :usr => Usr.new) | ||
end | ||
|
||
def create | ||
@user = User.new(params[:user]) | ||
@user.valid? | ||
if @user.errors.empty? | ||
@user.save | ||
flash[:notice] = "Account registered!" | ||
redirect_to_target_or_default @user | ||
else | ||
render :action => :new | ||
end | ||
end | ||
|
||
def validate | ||
@user = User.new(params[:user]) | ||
@user.valid? | ||
errors = {} | ||
@user.errors.each do |attr, msg| | ||
errors[attr] = msg | ||
end | ||
render :text => errors.to_json | ||
end | ||
|
||
def regions | ||
@regions = Region.all(:conditions => {:country_id => params[:country_id]}) | ||
render :layout => false | ||
end | ||
|
||
def cities | ||
@cities = City.all(:conditions => {:region_id => params[:region_id]}) | ||
render :layout => false | ||
end | ||
|
||
|
||
def edit | ||
@user = current_user | ||
end | ||
|
||
def update | ||
@user = User.find(current_user.id) | ||
if @user.update_attributes(params[:user]) | ||
flash[:notice] = "Account updated!" | ||
redirect_to user_path(@user) | ||
else | ||
render :action => :edit | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
= options_for_select(@cities.collect{|c| [c.name, c.id] }) |
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,52 @@ | ||
:javascript | ||
$(document).ready(function() { | ||
/* | ||
$('#user_ucontact_attributes_country_id').change(function() { | ||
$.get("#{regions_registration_path}", {country_id: this.value}, function(data) { | ||
$('#user_ucontact_attributes_region_id').html(data) | ||
}) | ||
}) | ||
$('#user_ucontact_attributes_region_id').change(function() { | ||
$.get("#{cities_registration_path}", {region_id: this.value}, function(data) { | ||
$('#user_ucontact_attributes_city_id').html(data) | ||
}) | ||
}) | ||
*/ | ||
|
||
$("#user_login_email").rules("add", { | ||
required: true, email: true | ||
}) | ||
$('#user_password_confirmation').rules("remove", "required") | ||
}) | ||
|
||
%h1 | ||
Edit Profile | ||
|
||
- semantic_form_for @user, :url => registration_path, :live_validations => true do |f| | ||
|
||
- f.inputs :name => "Login Information" do | ||
= f.input :username | ||
= f.input :login_email | ||
= f.input :password | ||
= f.input :password_confirmation | ||
|
||
- f.inputs :name => "Account Information", :for => :usr do |uf| | ||
= uf.input :first_name | ||
= uf.input :last_name | ||
= uf.input :one_line_bio | ||
|
||
- f.inputs :name => "Contact Information", :for => :ucontact do |cf| | ||
= cf.input :country | ||
= cf.input :city | ||
= cf.input :state | ||
= cf.input :street1 | ||
= cf.input :street2 | ||
= cf.input :zip | ||
= cf.input :telnum1 | ||
= cf.input :telnum1_type, :as => :select, :collection => Ucontact::OP_PHONE_TYPES, :prompt => false | ||
= cf.input :telnum2 | ||
= cf.input :telnum2_type, :as => :select, :collection => Ucontact::OP_PHONE_TYPES, :prompt => false | ||
= cf.input :webpage1 | ||
= cf.input :time_zone, :as => :time_zone | ||
|
||
= f.buttons |
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,90 @@ | ||
%style | ||
:sass | ||
.password_strength_1 | ||
color: #ccc | ||
.password_strength_2 | ||
color: #faa | ||
.password_strength_3 | ||
color: #f60 | ||
.password_strength_4 | ||
color: #3c0 | ||
.password_strength_5 | ||
color: #3f0 | ||
|
||
.validation-message | ||
color: #f00 | ||
.validation-message.success | ||
color: #0a0 | ||
|
||
= javascript_include_tag "jquery.password_strength" | ||
|
||
:javascript | ||
function add_message_to_field(field, message, is_success) | ||
{ | ||
field = $(field); | ||
message_container = field.next('.validation-message'); | ||
if (!message_container.length) { | ||
field.after('<span class="validation-message"></span>'); | ||
message_container = field.next('.validation-message'); | ||
} | ||
message_container.html(message); | ||
message_container.toggleClass('success', is_success); | ||
} | ||
|
||
$(document).ready(function() { | ||
$('#user_password').after('<span id="password_strength" />'); | ||
$('#user_password').password_strength({'container': '#password_strength'}) | ||
|
||
$('#user_username').blur(function() { | ||
$.post("#{validate_registration_path}", {'user[username]': this.value}, function(data) { | ||
if (data.username) { | ||
add_message_to_field('#user_username', data.username, false); | ||
} else { | ||
add_message_to_field('#user_username', "OK", true); | ||
} | ||
}, "json") | ||
}) | ||
|
||
$('#user_login_email').blur(function() { | ||
var self = this; | ||
$.post("#{validate_registration_path}", {'user[login_email]': this.value}, function(data) { | ||
if (data["login_email"]) { | ||
add_message_to_field(self, data["login_email"], false); | ||
} else { | ||
add_message_to_field(self, "OK", true); | ||
} | ||
}, "json") | ||
}) | ||
|
||
$('#user_password_confirmation').blur(function() { | ||
if (this.value) { | ||
if ($('#user_password').val() == this.value) { | ||
add_message_to_field(this, "Confirmation OK", true); | ||
} else { | ||
add_message_to_field(this, "Password doesn't match confirmation.", false); | ||
} | ||
} | ||
}) | ||
|
||
}) | ||
|
||
%h1 | ||
Registration | ||
|
||
- semantic_form_for @user, :url => registration_path, :html => {:class => 'validate'} do |f| | ||
|
||
- f.inputs do | ||
= f.input :username | ||
= f.input :login_email | ||
- f.inputs :for => :usr do |uf| | ||
= uf.input :first_name | ||
= uf.input :last_name | ||
= uf.input :one_line_bio | ||
|
||
= f.input :password | ||
= f.input :password_confirmation | ||
|
||
= f.buttons | ||
|
||
Already have account? | ||
= link_to "Log in", new_user_session_path |
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 @@ | ||
= options_for_select(@regions.collect{|r| [r.name, r.id] }) |