diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d2c7289..8a090fc 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -6,11 +6,6 @@ class UsersController < ApplicationController skip_before_action :verify_authenticity_token, only: [:verify_login] def show - if current_user - render json: { id: current_user.id, name: current_user.display_name, admin: current_user.admin? } - else - render json: nil - end end def login @@ -48,11 +43,15 @@ class UsersController < ApplicationController def create @user = User.new(user_params) - if @user.save - set_current_user(@user) - redirect_to root_path, notice: 'User was successfully created.' - else - render action: :new + respond_to do |format| + if @user.save + set_current_user(@user) + format.html { redirect_to root_path, notice: 'User created.' } + format.json { render :show, status: :created, location: @user } + else + format.html { render :new } + format.json { render json: @user.errors, status: :unprocessable_entity } + end end end @@ -62,10 +61,15 @@ class UsersController < ApplicationController def update @user = current_user - if @user.update(user_params) - redirect_to root_path, notice: 'User account updated' - else - render action: 'edit' + + respond_to do |format| + if @user.update(user_params) + format.html { redirect_to root_path, notice: 'User updated.' } + format.json { render :show, status: :created, location: @user } + else + format.html { render :edit } + format.json { render json: @user.errors, status: :unprocessable_entity } + end end end diff --git a/app/javascript/components/App.vue b/app/javascript/components/App.vue index 6a5c8e0..3df7376 100644 --- a/app/javascript/components/App.vue +++ b/app/javascript/components/App.vue @@ -33,12 +33,6 @@ }) }, - methods: { - ...mapMutations([ - 'setUser' - ]) - }, - watch: { isLoading(val) { if (val) { @@ -51,7 +45,7 @@ created() { if (this.user === null && this.authChecked === false) { - this.loadResource(api.getCurrentUser().then(user => this.setUser(user))); + this.checkAuthentication(); } // Hard coded values taken directly from Bulma css diff --git a/app/javascript/components/AppNavbar.vue b/app/javascript/components/AppNavbar.vue index 8c076db..4125205 100644 --- a/app/javascript/components/AppNavbar.vue +++ b/app/javascript/components/AppNavbar.vue @@ -13,14 +13,14 @@ diff --git a/app/javascript/components/AppValidationErrors.vue b/app/javascript/components/AppValidationErrors.vue new file mode 100644 index 0000000..661bbfb --- /dev/null +++ b/app/javascript/components/AppValidationErrors.vue @@ -0,0 +1,21 @@ + + + \ No newline at end of file diff --git a/app/javascript/components/IngredientEdit.vue b/app/javascript/components/IngredientEdit.vue index 4fd70ba..28c09ee 100644 --- a/app/javascript/components/IngredientEdit.vue +++ b/app/javascript/components/IngredientEdit.vue @@ -2,6 +2,8 @@

{{action}} {{ingredient.name || "[Unnamed Ingredient]"}}

+ +
@@ -143,6 +145,11 @@ required: true, type: Object }, + validationErrors: { + required: false, + type: Object, + default: {} + }, action: { required: false, type: String, diff --git a/app/javascript/components/LogEdit.vue b/app/javascript/components/LogEdit.vue index dc89660..4536b10 100644 --- a/app/javascript/components/LogEdit.vue +++ b/app/javascript/components/LogEdit.vue @@ -4,6 +4,8 @@

Creating Log for {{ log.recipe.name }}

+ +
@@ -38,7 +40,12 @@ log: { required: true, type: Object - } + }, + validationErrors: { + required: false, + type: Object, + default: {} + }, }, components: { diff --git a/app/javascript/components/TheAdminUserEditor.vue b/app/javascript/components/TheAdminUserEditor.vue new file mode 100644 index 0000000..12d0159 --- /dev/null +++ b/app/javascript/components/TheAdminUserEditor.vue @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file diff --git a/app/javascript/components/TheAdminUserList.vue b/app/javascript/components/TheAdminUserList.vue new file mode 100644 index 0000000..c5c3715 --- /dev/null +++ b/app/javascript/components/TheAdminUserList.vue @@ -0,0 +1,55 @@ + + + + + \ No newline at end of file diff --git a/app/javascript/components/TheIngredientCreator.vue b/app/javascript/components/TheIngredientCreator.vue index 435f600..24c7afa 100644 --- a/app/javascript/components/TheIngredientCreator.vue +++ b/app/javascript/components/TheIngredientCreator.vue @@ -1,7 +1,7 @@