Code Monkey home page Code Monkey logo

Comments (4)

richlove1 avatar richlove1 commented on June 23, 2024

OK so I put in a temporary fix... not sure if it's what we would want but it works....I've put in an error_redirect variable in the user update form then added code to check for this in postIndex() and redirect if present otherwise default to 'user/create'.

public function postIndex()
{
    $user = new User;

    $user->username = Input::get( 'username' );
    $user->email = Input::get( 'email' );
    $user->password = Input::get( 'password' );

    // The password confirmation will be removed from model
    // before saving. This field will be used in Ardent's
    // auto validation.
    $user->password_confirmation = Input::get( 'password_confirmation' );

    // Save if valid. Password field will be hashed before save
    $user->save();

    if ( $user->id )
    {
        // Redirect with success message, You may replace "Lang::get(..." for your custom message.
        return Redirect::to('user/login')
            ->with( 'notice', Lang::get('confide::confide.alerts.account_created') );
    }
    else
    {
        // Get validation errors (see Ardent package)
        $error = $user->errors()->all();

        // Default to redirect to user/create or redirect elsewhere if defined in the form
        $redirectTo = Input::get('error_redirect') ? Input::get('error_redirect') : 'user/create';

        return Redirect::to($redirectTo)
            ->withInput(Input::except('password'))
            ->with( 'error', $error );
    }
}

from laravel-4-bootstrap-starter-site.

richlove1 avatar richlove1 commented on June 23, 2024

Actually looking at this, I think it's more involved.... postIndex() is trying to handle the create user form submission and the update user form submission. The redirects and messages on success and failure relate to creating a new user, the functionality doesn't stand for the user update.

Not sure if there should be a separate function to handle the update ... although I understand this is supposed to be a restful controller.

I think perhaps this function should be renamed postCreate() and the creation form should submit to that then the functionality in postIndex() should be rewritten to handle the user update form.

(By the way, I'm happy to get involved in code changes but I'm not sure how to do this in terms of sending pull request etc). I've made a few changes here and there locally which I should probably feed back.

from laravel-4-bootstrap-starter-site.

richlove1 avatar richlove1 commented on June 23, 2024

Think this is also related to #63

from laravel-4-bootstrap-starter-site.

richlove1 avatar richlove1 commented on June 23, 2024

I was going to add in a postIndex() along the lines of:

/**
 * Updates user
 *
 */
public function postIndex()
{

    $user = Auth::user();
    $user->username = Input::get( 'username' );
    $user->email = Input::get( 'email' );
    $user->password = Input::get( 'password' );
    $user->password_confirmation = Input::get( 'password_confirmation' );*/

    if ( $user->save() )
    {
        ...
    }
    else
    {
        ...
    }
}

but user->save() fails/returns false. Just reading a little about Ardent (I need to read more) and it appears you should just be able to use the form fields but not sure if this allows you to update email/username fields.

from laravel-4-bootstrap-starter-site.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.