Permalink
Browse files

username validation

  • Loading branch information...
1 parent ef9ea54 commit 15a9465229d2534b04d44efa44c2bec53c35787e @evanw committed Aug 13, 2012
Showing with 11 additions and 4 deletions.
  1. +1 −1 game/src/entities/bouncyrocket.js
  2. +1 −1 rails/app/models/level.rb
  3. +7 −0 rails/app/models/user.rb
  4. +2 −2 rails/config/routes.rb
@@ -28,7 +28,7 @@ function drawBouncyRocket(c, isBlue) {
BouncyRocket.subclasses(Rocket);
function BouncyRocket(center, target, heading, launcher) {
- Rocket.prototype.constructor.call(this, center, target, heading, BOUNCY_ROCKET_MAX_ROTATION, ENEMY_BOUNCY_ROCKET),
+ Rocket.prototype.constructor.call(this, center, target, heading, BOUNCY_ROCKET_MAX_ROTATION, ENEMY_BOUNCY_ROCKET);
this.velocity = new Vector(BOUNCY_ROCKET_SPEED * Math.cos(heading), BOUNCY_ROCKET_SPEED * Math.sin(heading));
this.launcher = launcher;
this.hitsUntilExplodes = BOUNCY_ROCKET_HEALTH;
@@ -24,7 +24,7 @@ def clean_data
end
def title_content
- errors.add(:title, "Title can only contain letters, numbers, and spaces") if not self.title =~ /^[^\W_](([^\W_]| )*[^\W_])?$/
+ errors.add(:title, "can only contain letters, numbers, and spaces") if not self.title =~ /^[^\W_](([^\W_]| )*[^\W_])?$/
end
def determine_position
View
@@ -11,6 +11,7 @@ class User < ActiveRecord::Base
has_many :levels, :dependent => :destroy
has_many :statistics, :dependent => :destroy
+ validate :username_content
validates_uniqueness_of :username, :on => :create, :message => "must be unique"
def normalize_level_positions
@@ -32,4 +33,10 @@ def email=(str)
write_attribute(:email, str.downcase)
end
+ private
+
+ def username_content
+ errors.add(:username, "can only contain letters, numbers, and spaces") if not self.username =~ /^[^\W_](([^\W_]| )*[^\W_])?$/
+ end
+
end
View
@@ -6,8 +6,8 @@
match 'edit/:levelname' => 'users#edit_level', :via => :get
match 'edit/:levelname' => 'users#update_level', :via => :put
- match 'data/:username' => 'users#menu_data'
- match 'data/:username/:levelname' => 'users#level_data', :via => :get
+ match 'data/:username' => 'users#menu_data', :username => /[^\/]+/
+ match 'data/:username/:levelname' => 'users#level_data', :via => :get, :username => /[^\/]+/
match 'stats' => 'users#get_stats', :via => :get
match 'stats' => 'users#set_stats', :via => :put

0 comments on commit 15a9465

Please sign in to comment.