forked from External/greenlight
add support for deploying to a subdirectory
This commit is contained in:
@ -3,7 +3,7 @@ class UsersController < ApplicationController
|
||||
before_action :find_user, only: [:edit, :update]
|
||||
before_action :ensure_unauthenticated, only: [:new, :create]
|
||||
|
||||
# POST /users
|
||||
# POST /u
|
||||
def create
|
||||
# Verify that GreenLight is configured to allow user signup.
|
||||
return unless Rails.configuration.allow_user_signup
|
||||
@ -28,7 +28,7 @@ class UsersController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
# GET /users/:user_uid/edit
|
||||
# GET /u/:user_uid/edit
|
||||
def edit
|
||||
if current_user
|
||||
redirect_to current_user.room unless @user == current_user
|
||||
@ -37,41 +37,40 @@ class UsersController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH /users/:user_uid
|
||||
# PATCH /u/:user_uid
|
||||
def update
|
||||
# Update account information if passed.
|
||||
@user.name = user_params[:name] if user_params[:name]
|
||||
@user.email = user_params[:email] if user_params[:email]
|
||||
@user.image = user_params[:image] if user_params[:image]
|
||||
if params[:setting] == "password"
|
||||
# Update the users password.
|
||||
errors = {}
|
||||
|
||||
# Custom errors not generated by validations.
|
||||
errors = {}
|
||||
|
||||
# Verify that the provided password is correct.
|
||||
if user_params[:password]
|
||||
if @user.authenticate(user_params[:password])
|
||||
# Verify that the new passwords match.
|
||||
if user_params[:new_password] == user_params[:password_confirmation]
|
||||
@user.password = user_params[:new_password]
|
||||
else
|
||||
# New passwords don't match.
|
||||
errors[:password_confirmation] = "'s don't match"
|
||||
errors[:password_confirmation] = "doesn't match"
|
||||
end
|
||||
else
|
||||
# Original password is incorrect, can't update.
|
||||
errors[:password] = "is incorrect"
|
||||
end
|
||||
end
|
||||
|
||||
if @user.save!
|
||||
# Notify the use that their account has been updated.
|
||||
redirect_to edit_user_path(@user), notice: "Information successfully updated."
|
||||
if errors.empty? && @user.save
|
||||
# Notify the use that their account has been updated.
|
||||
redirect_to edit_user_path(@user), notice: "Information successfully updated."
|
||||
else
|
||||
# Append custom errors.
|
||||
errors.each do |k, v| @user.errors.add(k, v) end
|
||||
render :edit
|
||||
end
|
||||
else
|
||||
# Append custom errors.
|
||||
errors.each do |k, v| @user.errors.add(k, v) end
|
||||
|
||||
# Handle validation errors.
|
||||
render :edit
|
||||
# Update the core user attributes.
|
||||
if @user.update_attributes(user_params)
|
||||
redirect_to edit_user_path(@user), notice: "Information successfully updated."
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user