hipsterjazzbo / LaraParse

LaraParse provides a nice integration for using Parse (parse.com) with Laravel 5+
MIT License
27 stars 19 forks source link

Roles #18

Closed iamraffe closed 9 years ago

iamraffe commented 9 years ago

I don't know if this is not within the scope of LaraParse but I am setting a three level website (users, managers and administrators) and Roles play a huge part in this.

I have modified the code on the Registrar to look like this:

/**
 * Create a new user instance after a valid registration.
 *
 * Assign Administrator Role if wanted/needed.
 *
 * @param  array $data
 *
 * @param  bool $isAdmin
 *
 * @return User
 */
public function create(array $data, $isAdmin = false)
{
    $userSubclass   = ParseObject::getRegisteredSubclass('_User');
    $user           = new $userSubclass;
    $user->username = $data['email'];
    $user->email    = $data['email'];
    $user->password = $data['password'];
    if(isset($data['name'])){
        $fullName = explode(" ", $data['name']);
        $user->name = $fullName[0];
        $user->lastname = $fullName[1];
    }
    if(isset($data['id'])){
        $user->facebookId = $data['id'];
        $user->pictureURL = $data['avatar'];
        $user->name = $data['first_name'];
        $user->lastname = $data['last_name'];
    }
    $user->signUp();

    if(!$isAdmin){
        $query = new ParseQuery('_Role');
        $adminRole = new ParseRole();
        $adminRole = $query->equalTo("name", "Administrator")->first(true);
        $adminRole->getUsers()->add($user);
        $adminRole->save(true);
    }

    return $user;
}

I don't know if this is the best implementation, so if anyone has a suggestion (mostly on security), since this is my first time working with the Parse SDK, I would greatly appreciate it.

If not, I hope this can help someone get the Roles working quickly.

hipsterjazzbo commented 9 years ago

This implementation isn't something we'll do exactly, as it's very specific to your use case. But I'm hoping to get to roles at some point.

iamraffe commented 9 years ago

I would love to help in any way I can when that time comes.

Cheers

On Wed, Jun 10, 2015 at 1:12 AM, Caleb Fidecaro notifications@github.com wrote:

This implementation isn't something we'll do exactly, as it's very specific to your use case. But I'm hoping to get to roles at some point.

— Reply to this email directly or view it on GitHub https://github.com/HipsterJazzbo/LaraParse/issues/18#issuecomment-110529544 .