Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3748291
D27.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D27.diff
View Options
diff --git a/app/Models/Identity.php b/app/Models/Identity.php
new file mode 100644
--- /dev/null
+++ b/app/Models/Identity.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace AuthGrove\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class Identity extends Model {
+
+ use FindableByAttribute;
+
+ /**
+ * The database table used by the model.
+ *
+ * @var string
+ */
+ protected $table = 'identities';
+
+ /**
+ * The attributes that are mass assignable.
+ *
+ * @var array
+ */
+ protected $fillable = ['uuid', 'user_id', 'username', 'fullname'];
+
+ /**
+ * The user linked to this identity.
+ *
+ * @var AuthGrove\Models\User
+ */
+ private $user;
+
+ /**
+ * Gets the user linked to this identity.
+ *
+ * @return AuthGrove\Models\User
+ */
+ public function getUser () {
+ if ($this->user === null) {
+ $this->user = User::find($this->attributes['user_id']);
+ }
+ return $this->user;
+ }
+
+ /**
+ * Gets identity name.
+ *
+ * @retrun string
+ */
+ public function getName () {
+ if ($this->attributes['fullname'] !== "") {
+ return $this->attributes['fullname'];
+ }
+ return $this->attributes['username'];
+ }
+}
diff --git a/app/Models/User.php b/app/Models/User.php
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -94,6 +94,10 @@
return $this->attributes['username'];
}
+ ///
+ /// External source
+ ///
+
/**
* Tries to get the local user matching an external source.
*
@@ -115,4 +119,51 @@
$user = $source->getUser();
return true;
}
+
+ ///
+ /// Identities
+ ///
+
+ /**
+ * The currenty user identity
+ */
+ private $identity;
+
+ /**
+ * Gets identity name
+ *
+ * @retrun string
+ */
+ public function getIdentityOrAccountName () {
+ $identity = $this->getCurrentIdentity();
+ if ($identity === null) {
+ return $this->attributes['username'];
+ }
+ return $identity->getName();
+ }
+
+ /**
+ * Autoselects an identity.
+ *
+ * Sets it to identity property.
+ */
+ public function autoselectsIdentity () {
+ $this->identity = Identity::where(['user_id' => $this->id])->first();
+ }
+
+ /**
+ * Gets the full name of an identity, or if not defined, the username.
+ *
+ * If the user hasn't selected an identity yet, we use the user's username.
+ *
+ * @return AuthGrove\Models\Identity|null
+ */
+ public function getCurrentIdentity () {
+ if ($this->identity = null) {
+ // Tries to autoselect identity if there is only one
+ // or if one is configured to be used by default.
+ $this->autoselectsIdentity();
+ }
+ return $this->identity;
+ }
}
diff --git a/composer.json b/composer.json
--- a/composer.json
+++ b/composer.json
@@ -8,7 +8,7 @@
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"artisaninweb/laravel-enum": "1.0.*",
- "keruald/globalfunctions": "~0.3",
+ "keruald/globalfunctions": "~0.4",
"laravel/socialite": "^2.0"
},
"require-dev": {
diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php
--- a/database/factories/ModelFactory.php
+++ b/database/factories/ModelFactory.php
@@ -20,3 +20,12 @@
'remember_token' => str_random(10),
];
});
+
+$factory->define(AuthGrove\Models\Identity::class, function ($faker) {
+ return [
+ 'uuid' => \Keruald\uuid(),
+ 'user_id' => $faker->user_id,
+ 'username' => $faker->username,
+ 'fullname' => $faker->fullname,
+ ];
+});
diff --git a/database/migrations/2015_07_12_000000_create_identities_table.php b/database/migrations/2015_07_12_000000_create_identities_table.php
new file mode 100644
--- /dev/null
+++ b/database/migrations/2015_07_12_000000_create_identities_table.php
@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateIdentitiesTable extends Migration {
+
+ /**
+ * Runs the migrations.
+ *
+ * @return void
+ */
+ public function up() {
+ Schema::create('identities', function(Blueprint $table) {
+ $table->increments('id');
+ $table->string('uuid');
+ $table->integer('user_id');
+ $table->string('username');
+ $table->string('fullname');
+ $table->timestamps();
+ $table->softDeletes();
+ });
+ }
+
+ /**
+ * Reverses the migrations.
+ *
+ * @return void
+ */
+ public function down() {
+ Schema::drop('identities');
+ }
+
+}
diff --git a/resources/views/app.blade.php b/resources/views/app.blade.php
--- a/resources/views/app.blade.php
+++ b/resources/views/app.blade.php
@@ -39,7 +39,7 @@
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
- <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{ Auth::user()->getName() }} <span class="caret"></span></a>
+ <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{ Auth::user()->getIdentityOrAccountName() }} <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="@authurl('logout')">@lang('panel.logout')</a></li>
</ul>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 17, 07:55 (21 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2248928
Default Alt Text
D27.diff (5 KB)
Attached To
Mode
D27: WIP: identities
Attached
Detach File
Event Timeline
Log In to Comment