resolved user.rb conflict
This commit is contained in:
parent
bfdef8dc68
commit
7bcda2794f
4 changed files with 40 additions and 11 deletions
|
@ -2,8 +2,8 @@ class UserController < ApplicationController
|
||||||
layout 'site'
|
layout 'site'
|
||||||
|
|
||||||
before_filter :authorize, :only => [:preferences, :api_details, :api_gpx_files]
|
before_filter :authorize, :only => [:preferences, :api_details, :api_gpx_files]
|
||||||
before_filter :authorize_web, :only => [:edit, :account, :go_public, :view, :diary]
|
before_filter :authorize_web, :only => [:edit, :account, :go_public, :view, :diary, :make_friend]
|
||||||
before_filter :require_user, :only => [:edit, :set_home, :account, :go_public]
|
before_filter :require_user, :only => [:edit, :set_home, :account, :go_public, :make_friend]
|
||||||
|
|
||||||
def save
|
def save
|
||||||
@user = User.new(params[:user])
|
@user = User.new(params[:user])
|
||||||
|
@ -164,7 +164,22 @@ class UserController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_friend
|
def make_friend
|
||||||
if params[:display_name]
|
|
||||||
|
if params[:display_name]
|
||||||
|
name = params[:display_name]
|
||||||
|
friend = Friend.new
|
||||||
|
friend.user_id = @user.id
|
||||||
|
friend.friend_user_id = User.find_by_display_name(name).id
|
||||||
|
unless @user.is_friends_with?(friend)
|
||||||
|
if friend.save
|
||||||
|
flash[:notice] = "#{name} is now your friend"
|
||||||
|
else
|
||||||
|
friend.add_error("adding a friend failed")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
flash[:notice] = "Your are already friends"
|
||||||
|
end
|
||||||
|
redirect_to :controller => 'user', :action => 'view'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,8 @@ class User < ActiveRecord::Base
|
||||||
has_many :traces
|
has_many :traces
|
||||||
has_many :diary_entries
|
has_many :diary_entries
|
||||||
has_many :messages, :foreign_key => :to_user_id
|
has_many :messages, :foreign_key => :to_user_id
|
||||||
|
has_many :friends
|
||||||
|
|
||||||
validates_confirmation_of :pass_crypt, :message => 'Password must match the confirmation password'
|
validates_confirmation_of :pass_crypt, :message => 'Password must match the confirmation password'
|
||||||
validates_uniqueness_of :display_name, :allow_nil => true
|
validates_uniqueness_of :display_name, :allow_nil => true
|
||||||
validates_uniqueness_of :email
|
validates_uniqueness_of :email
|
||||||
|
@ -18,7 +19,7 @@ class User < ActiveRecord::Base
|
||||||
self.timeout = Time.now
|
self.timeout = Time.now
|
||||||
self.token = User.make_token()
|
self.token = User.make_token()
|
||||||
end
|
end
|
||||||
|
|
||||||
def pass_crypt=(str)
|
def pass_crypt=(str)
|
||||||
write_attribute("pass_crypt", Digest::MD5.hexdigest(str))
|
write_attribute("pass_crypt", Digest::MD5.hexdigest(str))
|
||||||
end
|
end
|
||||||
|
@ -26,7 +27,7 @@ class User < ActiveRecord::Base
|
||||||
def pass_crypt_confirmation=(str)
|
def pass_crypt_confirmation=(str)
|
||||||
write_attribute("pass_crypt_confirm", Digest::MD5.hexdigest(str))
|
write_attribute("pass_crypt_confirm", Digest::MD5.hexdigest(str))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.authenticate(email, passwd)
|
def self.authenticate(email, passwd)
|
||||||
find(:first, :conditions => [ "email = ? AND pass_crypt = ?", email, Digest::MD5.hexdigest(passwd)])
|
find(:first, :conditions => [ "email = ? AND pass_crypt = ?", email, Digest::MD5.hexdigest(passwd)])
|
||||||
end
|
end
|
||||||
|
@ -34,7 +35,7 @@ class User < ActiveRecord::Base
|
||||||
def self.authenticate_token(token)
|
def self.authenticate_token(token)
|
||||||
find(:first, :conditions => [ "token = ? ", token])
|
find(:first, :conditions => [ "token = ? ", token])
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.make_token(length=30)
|
def self.make_token(length=30)
|
||||||
chars = 'abcdefghijklmnopqrtuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
chars = 'abcdefghijklmnopqrtuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
||||||
confirmstring = ''
|
confirmstring = ''
|
||||||
|
@ -58,9 +59,8 @@ class User < ActiveRecord::Base
|
||||||
el1['account_created'] = self.creation_time.xmlschema
|
el1['account_created'] = self.creation_time.xmlschema
|
||||||
return el1
|
return el1
|
||||||
end
|
end
|
||||||
|
|
||||||
def nearby(lat_range=1, lon_range=1)
|
def nearby(lat_range=1, lon_range=1)
|
||||||
|
|
||||||
if self.home_lon and self.home_lat
|
if self.home_lon and self.home_lat
|
||||||
nearby = User.find(:all, :conditions => "#{self.home_lon} > home_lon - #{lon_range} and #{self.home_lon} < home_lon + #{lon_range} and #{self.home_lon} > home_lon - #{lon_range} and #{self.home_lon} < home_lon + #{lon_range} and data_public = 1")
|
nearby = User.find(:all, :conditions => "#{self.home_lon} > home_lon - #{lon_range} and #{self.home_lon} < home_lon + #{lon_range} and #{self.home_lon} > home_lon - #{lon_range} and #{self.home_lon} < home_lon + #{lon_range} and data_public = 1")
|
||||||
else
|
else
|
||||||
|
@ -81,11 +81,21 @@ class User < ActiveRecord::Base
|
||||||
messages = Message.find(:all, :conditions => "message_read = 0")
|
messages = Message.find(:all, :conditions => "message_read = 0")
|
||||||
return messages
|
return messages
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_all_messages
|
def get_all_messages
|
||||||
messages = Message.find(:all, :conditions => "message_read = 0")
|
messages = Message.find(:all, :conditions => "message_read = 0")
|
||||||
return messages
|
return messages
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_friends_with?(new_friend)
|
||||||
|
res = false
|
||||||
|
@new_friend = new_friend
|
||||||
|
self.friends.each do |friend|
|
||||||
|
if friend.user_id == @new_friend.user_id
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -63,6 +63,7 @@ ActionController::Routing::Routes.draw do |map|
|
||||||
map.connect '/traces/tag/:tag/page/:page', :controller => 'trace', :action => 'list', :id => nil
|
map.connect '/traces/tag/:tag/page/:page', :controller => 'trace', :action => 'list', :id => nil
|
||||||
|
|
||||||
# user pages
|
# user pages
|
||||||
|
map.connect '/user/:display_name/make_friend', :controller => 'user', :action => 'make_friend'
|
||||||
map.connect '/user/:display_name', :controller => 'user', :action => 'view'
|
map.connect '/user/:display_name', :controller => 'user', :action => 'view'
|
||||||
map.connect '/user/:display_name/diary', :controller => 'user', :action => 'diary'
|
map.connect '/user/:display_name/diary', :controller => 'user', :action => 'diary'
|
||||||
map.connect '/user/:display_name/diary/newpost', :controller => 'diary_entry', :action => 'new'
|
map.connect '/user/:display_name/diary/newpost', :controller => 'diary_entry', :action => 'new'
|
||||||
|
|
|
@ -46,3 +46,6 @@ alter table users add column within_lon double default 2;
|
||||||
alter table users add column within_lat double default 2;
|
alter table users add column within_lat double default 2;
|
||||||
|
|
||||||
create table messages (id bigint not null auto_increment, user_id bigint(20) not null, from_user_id bigint(20) not null, title varchar(255), body text, sent_on datetime, message_read boolean default 0, primary key(id));
|
create table messages (id bigint not null auto_increment, user_id bigint(20) not null, from_user_id bigint(20) not null, title varchar(255), body text, sent_on datetime, message_read boolean default 0, primary key(id));
|
||||||
|
|
||||||
|
create table friends (id bigint not null auto_increment, user_id bigint(20) not null, friend_user_id(20) not null, primary key(id));
|
||||||
|
create index user_id_idx on friends(friend_user_id);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue