diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.scss index 1f8f00c4..50e9fc13 100644 --- a/app/assets/stylesheets/users.scss +++ b/app/assets/stylesheets/users.scss @@ -1,4 +1,10 @@ .user { + .error { + p { + font-size: 14px; + color: red; + } + } .description { p { font-size: 14px; diff --git a/app/controllers/landing_controller.rb b/app/controllers/landing_controller.rb index 217ce1f6..a9321817 100644 --- a/app/controllers/landing_controller.rb +++ b/app/controllers/landing_controller.rb @@ -22,15 +22,13 @@ class LandingController < ApplicationController render_meeting end - def room - render_room - end - def admin? @user == current_user end helper_method :admin? + private + def render_meeting @resource = params[:resource] @meeting_token = params[:id] || @meeting_token = helpers.new_meeting_token @@ -47,5 +45,5 @@ class LandingController < ApplicationController end render :action => 'room' end - + end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 0b79b493..a5ebaaa7 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -3,7 +3,7 @@ class SessionsController < ApplicationController @user = User.from_omniauth(request.env['omniauth.auth']) if @user.persisted? session[:user_id] = @user.id - redirect_to controller: 'landing', action: 'room', id: @user.username + redirect_to controller: 'landing', action: 'index', id: @user.username, resource: 'rooms' else @user.save! session[:user_id] = @user.id diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 12cc6c63..98fba033 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -9,8 +9,9 @@ class UsersController < ApplicationController # PATCH/PUT /users/1.json def update if @user.update(user_params) - redirect_to controller: 'landing', action: 'room', id: @user.username + redirect_to controller: 'landing', action: 'index', id: @user.username, resource: 'rooms' else + @error = @user.errors.first[1] rescue nil render :edit end end diff --git a/app/models/user.rb b/app/models/user.rb index c0d1a87b..9cfb2add 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,10 @@ class User < ApplicationRecord - validates :username, uniqueness: true + validates :username, + uniqueness: { message: "this username is taken" }, + format: { with: /\A^[0-9a-z-_]+\Z/, + message: "Only allows lowercase alphanumeric characters with dashes and underscores", + allow_blank: true } def self.from_omniauth(auth_hash) user = find_or_initialize_by(uid: auth_hash['uid'], provider: auth_hash['provider']) diff --git a/app/views/landing/meeting.html.erb b/app/views/landing/meeting.html.erb index f2eb6687..44aae469 100644 --- a/app/views/landing/meeting.html.erb +++ b/app/views/landing/meeting.html.erb @@ -7,7 +7,11 @@ <% if !current_user.nil? %> Hello <%= current_user.name %> <%= link_to "Logout", user_logout_url() %> -
<%= error %>
+This username will be used to identify your personal room