Skip to content

Commit 5313ed3

Browse files
committed
You can now add about information.
1 parent 5e7909c commit 5313ed3

4 files changed

Lines changed: 71 additions & 10 deletions

File tree

Rakefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ namespace :db do
4545
:email => "steve@steveklabnik.com",
4646
:password => "password",
4747
:password_confirmation => "password",
48-
:admin => true
48+
:admin => true,
49+
:about => "I hack on Hackety Hack!"
4950
})
5051

5152
#we're also going to make a regular user too
@@ -54,6 +55,7 @@ namespace :db do
5455
:email => "somebody@example.com",
5556
:password => "password",
5657
:password_confirmation => "password",
58+
:about => "I'm just a regular person!"
5759
})
5860
#make an initial Post, with a comment
5961
require 'models/post'

controllers/hacker.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,30 @@
1010
haml :"hackers/show"
1111
end
1212

13+
#update a hacker's information
14+
post '/hackers/update' do
15+
#you have to be logged in to update your info
16+
require_login! :return => "/hackers/update"
17+
18+
#do they want to update their password
19+
unless params[:password].nil?
20+
if params[:password][:new] == params[:password][:confirm]
21+
current_user.password = params[:password][:new]
22+
current_user.save
23+
flash[:notice] = "Password updated!"
24+
else
25+
flash[:notice] = "Password confirmation didn't match!"
26+
end
27+
else
28+
current_user.update_attributes(:about => params[:hacker][:about])
29+
current_user.save
30+
flash[:notice] = "About information updated!"
31+
end
32+
33+
redirect "/hackers/#{current_user.username}"
34+
35+
end
36+
1337
#this lets you follow a Hacker
1438
get '/hackers/:name/follow' do
1539
#we have to be logged in to follow someone

models/hacker.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ class Hacker
99
#and a unique email
1010
key :email, String, :unique => true
1111

12+
#a little bit about the Hacker
13+
key :about, String
14+
1215
#we don't store the passwords themselves, we store a 'hash' of them. More about this down in password=
1316
key :hashed_password, String
1417
key :salt, String

views/hackers/show.haml

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,44 @@
1-
%p= @hacker.username + "'s page"
2-
%p
3-
%img{:src => @hacker.gravatar_url}
1+
%h1= @hacker.username + "'s page"
2+
%img{:src => @hacker.gravatar_url}
3+
%h2 About #{@hacker.username}:
4+
%p= @hacker.about
5+
%hr
46
%p Following: <a href="/hackers/#{@hacker.username}/following">#{@hacker.following.count}</a>
57
%p Followers: <a href="/hackers/#{@hacker.username}/followers">#{@hacker.followers.count}</a>
6-
7-
- if logged_in? && @hacker.username != current_user.username
8-
%a{:href => "/messages/new/to/#{@hacker.username}" }= "Send #{@hacker.username} a message"
9-
- if current_user.following? @hacker
10-
%a{:href => "/hackers/#{@hacker.username}/unfollow"} Unfollow #{@hacker.username}
8+
%hr
9+
- if logged_in?
10+
- if @hacker.username != current_user.username
11+
%a{:href => "/messages/new/to/#{@hacker.username}" }= "Send #{@hacker.username} a message"
12+
- if current_user.following? @hacker
13+
%a{:href => "/hackers/#{@hacker.username}/unfollow"} Unfollow #{@hacker.username}
14+
- else
15+
%a{:href => "/hackers/#{@hacker.username}/follow"} Follow #{@hacker.username}
1116
- else
12-
%a{:href => "/hackers/#{@hacker.username}/follow"} Follow #{@hacker.username}
17+
%h2 Your Account
18+
%p You can use these forms to update your information:
19+
%br
20+
%p
21+
%form{:action => "/hackers/update", :method => "POST"}
22+
%table
23+
%tr
24+
%td
25+
%label{:for => "password[new]"} New Password
26+
%td
27+
%input{:type => "password", :name => "password[new]"}
28+
%tr
29+
%td
30+
%label{:for => "password[confirm]"} Confirm New Password
31+
%td
32+
%input{:type => "password", :name => "password[confirm]"}
33+
%tr
34+
%td
35+
%td
36+
%input{:type => "submit", :value => "Change password"}
37+
%hr
38+
%p
39+
%form{:action => "/hackers/update", :method => "POST"}
40+
%label{:for => "hacker[about]"} About Me
41+
%br
42+
%textarea{:name => "hacker[about]", :rows => 10, :cols => 40}
43+
%br
44+
%input{:type => "submit", :value => "Update About"}

0 commit comments

Comments
 (0)