Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorraslam
     
    Hi,

    I want to add user model to the blog screencast tutorial. I want users to register and make a post as well as they can make a comment.

    Need an overview on how to do this. I'll try and do the detail work.

    thanx
    --
    raslam
    • CommentAuthorJeff
     

    Hey,

    For comments, it's pretty similar to the post model. You'll probably want to add a relationship between the post and comments. In the post model you should have:

    var $has_many = 'comments';
    

    and the comment model should have:

    var $belongs_to = 'post';
    

    along with a field in the comment table named post_id. Note that models can be separated with comas in the string.


    As for the user model, there is a rails tutorial that you can try to implement (that I based my user model off of). You can also implement similar relationship as with comments and posts.

    You'll probably want a 'password confirm' field when users register. The to do this, you have manually set password + password_confirmation fields in your controller when the user submits the forum (assuming the password fields don't exist):

    $this->user->set('password', $this->params['user']['password']);
    $this->user->set('password_repeat', $this->params['user']['password_confirmation']);
    

    This allows you to use getters/setters for these imaginary properties like so:

    function setPassword($value){
        $this->password = $value;
        $this->password_hash = sha1($value);
    }
    function setPassword_confirmation($value){
        $this->password_confirmation = $value;
    }
    

    bermi explained the getters/setters in more detail.

    As for user logins/logouts you can just use the session and store the user's id, and username. To validate to see if the user is logged in, just check the session data. It's best to put this method in your application_controller.php (in your apps folder). Then in your controllers, you can just call that method.

    For the model end of user authentication, you should also probably make a function that validates the username + password when the user tries to logged in.

    I think that's a good summary. :)

    • CommentAuthorraslam
     
    Thanks alot jeff, I am going for it.
    •  
      CommentAuthorkonus
     

    don't forget the next line in post_controller.php

    var $models = 'post, comment';
    

    apparently missing in the screen cast.