Skip to content

Commit

Permalink
Login and Logout
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicabarbalho committed Jun 13, 2012
1 parent 2388c4d commit 0ed9214
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -10,7 +10,7 @@
# Ignore the default SQLite database.
/db/*.sqlite3
*.swp
/db/schema.rb
db/schema.rb

# Ignore all logfiles and tempfiles.
/log/*.log
Expand Down
2 changes: 0 additions & 2 deletions Gemfile
Expand Up @@ -9,8 +9,6 @@ gem 'sqlite3'

gem 'json'

gem "has_friends-rails3", "~> 0.0.4"

# Gems used only for assets and not required
# in production environments by default.
group :assets do
Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Expand Up @@ -65,7 +65,6 @@ GEM
thor (>= 0.14.6)
guard-rspec (1.0.0)
guard (>= 1.1)
has_friends-rails3 (0.0.4)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
Expand Down Expand Up @@ -181,7 +180,6 @@ DEPENDENCIES
coffee-rails (~> 3.2.1)
factory_girl_rails (~> 1.7.0)
guard-rspec
has_friends-rails3 (~> 0.0.4)
jquery-rails
json
launchy (~> 2.1.0)
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/sessions_controller.rb
@@ -1,18 +1,19 @@
class SessionsController < ApplicationController
def new
@user = User.new
end

def create
user = login(params[:email], params[:password])
if user
redirect_back_or_to root_url, :notice => "Logged in!"
redirect_back_or_to users_path, :notice => "Logged in!"
else
flash.now.alert = "Email or password was invalid."
redirect_to(login_path, :notice => "Email or password invalid!")
end
end

def destroy
logout
redirect_to root_url, :notice => "Logged out!"
redirect_to home_index_path, :notice => "Logged out!"
end
end
11 changes: 0 additions & 11 deletions app/controllers/users_controller.rb
@@ -1,5 +1,4 @@
class UsersController < ApplicationController

# GET /users
# GET /users.json
def index
Expand Down Expand Up @@ -71,14 +70,4 @@ def destroy
format.json { head :no_content }
end
end

def activate
if @user = User.load_from_activation_token(params[:id])
@user.activate!
redirect_to(login_path, :notice => 'User was successfully activated.')
else
not_authenticated
end
end

end
5 changes: 3 additions & 2 deletions app/views/sessions/new.html.erb
@@ -1,4 +1,6 @@
<%= form_tag sessions_path do %>
<h1>Login</h1>

<%= form_tag sessions_path, :method => :post do %>
<div class="field">
<%= label_tag :email %>
<%= text_field_tag :email, params[:email] %>
Expand All @@ -14,4 +16,3 @@
<div class="actions"><%= submit_tag "Log in" %></div>
<% end %>


20 changes: 10 additions & 10 deletions config/initializers/sorcery.rb
Expand Up @@ -119,7 +119,7 @@
# specify username attributes, for example: [:username, :email].
# Default: `[:username]`
#
# user.username_attribute_names =
user.username_attribute_names = :email


# change *virtual* password attribute, the one which is used until an encrypted one is generated.
Expand Down Expand Up @@ -218,14 +218,14 @@
# Default: `nil`
#
# user.user_activation_mailer =


# when true sorcery will not automatically
# email activation details and allow you to
# manually handle how and when email is sent.
# Default: `false`
#
# user.activation_mailer_disabled =
# user.activation_mailer_disabled =


# activation needed email method on your mailer class.
Expand Down Expand Up @@ -282,17 +282,17 @@
# manually handle how and when email is sent
# Default: `false`
#
# user.reset_password_mailer_disabled =
# user.reset_password_mailer_disabled =



# reset password email
# reset password email
# method on your mailer
# class.
# Default: `:reset_password_email`
#
# user.reset_password_email_method_name =
# user.reset_password_email_method_name =



# how many seconds before the reset request expires. nil for never expires.
# Default: `nil`
#
Expand Down Expand Up @@ -347,7 +347,7 @@

# Unlock token mailer class
# Default: `nil`
#
#
# user.unlock_token_mailer = UserMailer

# -- activity logging --
Expand Down
1 change: 0 additions & 1 deletion config/routes.rb
@@ -1,6 +1,5 @@
CapybaraIntegration::Application.routes.draw do
get "home/index"

get "home/secret"

resources :users
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20120606195608_sorcery_core.rb
@@ -1,8 +1,8 @@
class SorceryCore < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :name, :null => false # if you use another field as a username, for example email, you can safely remove this field.
t.string :email, :default => nil # if you use this field as a username, you might want to make it :null => false.
t.string :name, :default => nil # if you use another field as a username, for example email, you can safely remove this field.
t.string :email, :null => false # if you use this field as a username, you might want to make it :null => false.
t.string :password, :default => nil
t.string :crypted_password, :default => nil
t.string :hometown, :default => nil
Expand Down
42 changes: 0 additions & 42 deletions db/migrate/20120606200918_create_has_friends_tables.rb

This file was deleted.

47 changes: 5 additions & 42 deletions db/schema.rb
Expand Up @@ -10,54 +10,17 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120606200918) do

create_table "friendship_messages", :force => true do |t|
t.string "body"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

create_table "friendship_relation_types", :force => true do |t|
t.integer "relation_id"
t.integer "friendship_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

create_table "friendships", :force => true do |t|
t.integer "user_id"
t.integer "friend_id"
t.integer "friendship_message_id"
t.datetime "requested_at"
t.datetime "accepted_at"
t.string "status"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

add_index "friendships", ["friend_id"], :name => "index_friendships_on_friend_id"
add_index "friendships", ["status"], :name => "index_friendships_on_status"
add_index "friendships", ["user_id"], :name => "index_friendships_on_user_id"

create_table "relation_types", :force => true do |t|
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

add_index "relation_types", ["name"], :name => "index_relation_types_on_name"
ActiveRecord::Schema.define(:version => 20120606195608) do

create_table "users", :force => true do |t|
t.string "name", :null => false
t.string "email"
t.string "name"
t.string "email", :null => false
t.string "password"
t.string "crypted_password"
t.string "hometown"
t.string "salt"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "friends_count", :default => 0, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

end
17 changes: 17 additions & 0 deletions spec/requests/friendship_spec.rb
@@ -0,0 +1,17 @@
require 'spec_helper'

describe "Friendship request" do
it "An user can do a friendship request" do
User.create(:email => "jessica@redu.com.br", :password => 123456)
User.create(:email => "testuser@redu.com.br", :password => 123456)
visit home_index_path
click_link "Log in"
fill_in 'Email', :with => 'jessica@redu.com.br'
fill_in 'Password', :with => 123456
click_button 'Log in'
click_link 'show'
current_path.should eq(user_show(1))
click_link 'add friend'
page.should have_content('waiting answerfor request')
end
end
38 changes: 38 additions & 0 deletions spec/requests/login_spec.rb
@@ -0,0 +1,38 @@
require 'spec_helper'

describe "Login" do
it "A person can log with a valid email and password" do
User.create(:email => "jessica@redu.com.br", :password => 123456)
visit home_index_path
click_link "Log in"
fill_in 'Email', :with => 'jessica@redu.com.br'
fill_in 'Password', :with => 123456
click_button 'Log in'
current_path.should eq(users_path)
page.should have_content("Logged in as jessica@redu.com.br")
end

it "A person can't log with invalid email or password" do
visit home_index_path
click_link "Log in"
fill_in 'Email', :with => 'jessica@redu.com.br'
fill_in 'Password', :with => 123456
click_button 'Log in'
current_path.should eq(login_path)
page.should have_content("Email or password invalid!")
end
end

describe "Logout" do
it "A person can logout" do
User.create(:email => "jessica@redu.com.br", :password => 123456)
visit home_index_path
click_link "Log in"
fill_in 'Email', :with => 'jessica@redu.com.br'
fill_in 'Password', :with => 123456
click_button 'Log in'
click_link 'Log out'
current_path.should eq(home_index_path)
page.should have_content("Logged out!")
end
end
4 changes: 2 additions & 2 deletions spec/requests/sign_ups_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'

describe "SignUps" do
it "any person can sign up on the app" do
it "Any person can sign up on the app" do
visit home_index_path
click_link "Sign up"
fill_in "Email", :with => "jessicar@redu.com.br"
Expand All @@ -16,7 +16,7 @@
click_link "Sign up"
fill_in "Email", :with => "jesica"
fill_in "Password", :with => "123"
click_on 'Create User'
click_button 'Create User'
current_path.should eq(users_path)
page.should have_content("Password is too short")
page.should have_content("Email is invalid")
Expand Down

0 comments on commit 0ed9214

Please sign in to comment.