예제 #1
0
 /**
  * Get signed in user's profile.
  */
 public function getUser(Request $request)
 {
     $user = User::find($request['user']['sub']);
     $user->roles = $user->roles()->get();
     $user->isAdmin = $user->hasRole('admin');
     $user->profile = $user->profile;
     $user->locations = $user->locations;
     $user->notifications = $user->getNotifications();
     $user->notificationsNotRead = $user->countNotificationsNotRead();
     $threads = Thread::forUser($user->id)->latest('updated_at')->get();
     $user->threads = $threads;
     $roles = Role::all(['id', 'display_name']);
     $activities = ActivityModel::where('user_id', $user->id)->get();
     return Response::json(['user' => $user, 'roles' => $roles, 'activities' => $activities]);
 }
예제 #2
0
 /**
  *
  * @param Request $request
  */
 public function destroyRole(Request $request)
 {
     $role = Role::findOrFail($request->input('id'));
     $role->delete();
     return Response::json(['success', true]);
 }
예제 #3
0
 /**
  * Create Email and Password Account.
  */
 public function signup(Request $request)
 {
     $validator = Validator::make($request->all(), ['displayName' => 'required', 'email' => 'required|email|unique:users,email', 'password' => 'required']);
     if ($validator->fails()) {
         return response()->json(['message' => $validator->messages()], 400);
     }
     $img = DefaultProfileImage::create($request->input('displayName'));
     $imageName = uniqid();
     $imgFile = public_path('uploads') . "/" . $imageName . '.png';
     $image = Image::make($img->encode());
     $image->save($imgFile, 100);
     $user = new User();
     $user->displayName = $request->input('displayName');
     $user->email = $request->input('email');
     $user->password = Hash::make($request->input('password'));
     $user->image = $imageName . '.png';
     $user->activation_code = $random_hash = md5(uniqid(rand(), true));
     $user->save();
     $role = Role::where('name', 'user')->first();
     $user->roles()->attach($role);
     $user_arr = $user->toArray();
     Mail::send("emails.welcome", $user_arr, function ($message) use($user_arr) {
         $message->from('*****@*****.**', "Site Name");
         $message->subject('Welcome to site name');
         $message->to($user_arr['email']);
     });
     //return response()->json(['token' => $this->createToken($user)]);
     return response()->json(["message" => "User created. We send a confirmation email. Check your email account.", 'token' => $this->createToken($user)]);
 }