refactoring de Name & Email vers Service & Account

This commit is contained in:
Bubka
2020-01-06 21:45:14 +01:00
parent 1a53aeed33
commit 9e7ea7d0fb
11 changed files with 53 additions and 53 deletions

View File

@@ -33,18 +33,18 @@ class QrCodecontroller extends Controller
$options[$option[0]] = $option[1]; $options[$option[0]] = $option[1];
} }
$email = $service = ''; $account = $service = '';
$serviceChunks = explode(':', str_replace('otpauth://totp/', '', $uriChunks[0])); $serviceChunks = explode(':', str_replace('otpauth://totp/', '', $uriChunks[0]));
if( count($serviceChunks) > 1 ) { if( count($serviceChunks) > 1 ) {
$email = $serviceChunks[1]; $account = $serviceChunks[1];
} }
$service = $serviceChunks[0]; $service = $serviceChunks[0];
if( strstr( $service, '@') ) { if( strstr( $service, '@') ) {
$email = $service; $account = $service;
$service = ''; $service = '';
} }
@@ -53,8 +53,8 @@ class QrCodecontroller extends Controller
} }
$twofaccount = (object) array( $twofaccount = (object) array(
'name' => $service, 'service' => $service,
'email' => $email, 'account' => $account,
'uri' => $uri, 'uri' => $uri,
'icon' => '', 'icon' => '',
'options' => $options 'options' => $options

View File

@@ -30,8 +30,8 @@ class TwoFAccountController extends Controller
public function store(Request $request) public function store(Request $request)
{ {
$twofaccount = TwoFAccount::create([ $twofaccount = TwoFAccount::create([
'name' => $request->name, 'service' => $request->service,
'email' => $request->email, 'account' => $request->account,
'uri' => $request->uri, 'uri' => $request->uri,
'icon' => $request->icon 'icon' => $request->icon
]); ]);

View File

@@ -9,7 +9,7 @@ class TwoFAccount extends Model
{ {
use SoftDeletes; use SoftDeletes;
protected $fillable = ['name', 'email', 'uri', 'icon']; protected $fillable = ['service', 'account', 'uri', 'icon'];
/** /**

View File

@@ -19,8 +19,8 @@ use Faker\Generator as Faker;
$factory->define(TwoFAccount::class, function (Faker $faker) { $factory->define(TwoFAccount::class, function (Faker $faker) {
return [ return [
'name' => $faker->unique()->domainName, 'service' => $faker->unique()->domainName,
'email' => $faker->safeEmail, 'account' => $faker->safeEmail,
'uri' => 'otpauth://totp/' . $faker->email . '?secret=' . $faker->regexify('[A-Z0-9]{16}') . '&issuer=test', 'uri' => 'otpauth://totp/' . $faker->email . '?secret=' . $faker->regexify('[A-Z0-9]{16}') . '&issuer=test',
]; ];
}); });

View File

@@ -15,9 +15,9 @@ class CreateTwoFAccountsTable extends Migration
{ {
Schema::create('twofaccounts', function (Blueprint $table) { Schema::create('twofaccounts', function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->string('name')->unique(); $table->string('service');
$table->string('uri'); $table->string('uri');
$table->string('email'); $table->string('account');
$table->string('icon')->nullable(); $table->string('icon')->nullable();
$table->timestamps(); $table->timestamps();
$table->softDeletes(); $table->softDeletes();

View File

@@ -14,32 +14,32 @@ class TwoFAccountsTableSeeder extends Seeder
$faker = \Faker\Factory::create(); $faker = \Faker\Factory::create();
TwoFAccount::create([ TwoFAccount::create([
'name' => $faker->unique()->domainName, 'service' => $faker->unique()->domainName,
'email' => $faker->email, 'account' => $faker->email,
'uri' => 'otpauth://totp/test@test.com?secret=A4GRFTVVRBGY7UIW&issuer=test', 'uri' => 'otpauth://totp/test@test.com?secret=A4GRFTVVRBGY7UIW&issuer=test',
'icon' => 'https://fakeimg.pl/64x64/' 'icon' => 'https://fakeimg.pl/64x64/'
]); ]);
TwoFAccount::create([ TwoFAccount::create([
'name' => $faker->unique()->domainName, 'service' => $faker->unique()->domainName,
'email' => $faker->email, 'account' => $faker->email,
'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHYVRBGY7UIW&issuer=test', 'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHYVRBGY7UIW&issuer=test',
'icon' => 'https://fakeimg.pl/64x64/' 'icon' => 'https://fakeimg.pl/64x64/'
]); ]);
TwoFAccount::create([ TwoFAccount::create([
'name' => $faker->unique()->domainName, 'service' => $faker->unique()->domainName,
'email' => $faker->email, 'account' => $faker->email,
'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHZVRBGY7UIW&issuer=test', 'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHZVRBGY7UIW&issuer=test',
'icon' => 'https://fakeimg.pl/64x64/' 'icon' => 'https://fakeimg.pl/64x64/'
]); ]);
TwoFAccount::create([ TwoFAccount::create([
'name' => $faker->unique()->domainName, 'service' => $faker->unique()->domainName,
'email' => $faker->email, 'account' => $faker->email,
'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHVIRBGY7UIW&issuer=test', 'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHVIRBGY7UIW&issuer=test',
'icon' => 'https://fakeimg.pl/64x64/' 'icon' => 'https://fakeimg.pl/64x64/'
]); ]);
TwoFAccount::create([ TwoFAccount::create([
'name' => $faker->unique()->domainName, 'service' => $faker->unique()->domainName,
'email' => $faker->email, 'account' => $faker->email,
'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHVVOBGY7UIW&issuer=test', 'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHVVOBGY7UIW&issuer=test',
'icon' => 'https://fakeimg.pl/64x64/' 'icon' => 'https://fakeimg.pl/64x64/'
]); ]);

View File

@@ -3,8 +3,8 @@
<figure class="image is-64x64" style="display: inline-block"> <figure class="image is-64x64" style="display: inline-block">
<img :src="icon"> <img :src="icon">
</figure> </figure>
<p class="is-size-4 has-text-grey-light">{{ name }}</p> <p class="is-size-4 has-text-grey-light">{{ service }}</p>
<p class="is-size-6 has-text-grey">{{ email }}</p> <p class="is-size-6 has-text-grey">{{ account }}</p>
<slot></slot> <slot></slot>
<div class="modal-action-links has-text-grey"> <div class="modal-action-links has-text-grey">
<router-link :to="{ name: 'edit', params: { twofaccountId: twofaccountid }}">Edit</router-link> <router-link :to="{ name: 'edit', params: { twofaccountId: twofaccountid }}">Edit</router-link>
@@ -18,6 +18,6 @@
return { return {
} }
}, },
props: ['twofaccountid', 'name', 'email', 'icon'], props: ['twofaccountid', 'service', 'account', 'icon'],
} }
</script> </script>

View File

@@ -5,8 +5,8 @@
<span v-for="account in accounts" class="button is-black twofaccount" > <span v-for="account in accounts" class="button is-black twofaccount" >
<span @click.stop="getAccount(account.id)"> <span @click.stop="getAccount(account.id)">
<img :src="account.icon"> <img :src="account.icon">
{{ account.name }} {{ account.service }}
<span class="is-family-primary is-size-7 has-text-grey">{{ account.email }}</span> <span class="is-family-primary is-size-7 has-text-grey">{{ account.account }}</span>
</span> </span>
<a v-on:click="deleteAccount(account.id)">Delete</a> <a v-on:click="deleteAccount(account.id)">Delete</a>
</span> </span>
@@ -15,9 +15,9 @@
<modal v-model="ShowTwofaccountInModal"> <modal v-model="ShowTwofaccountInModal">
<twofaccount-show <twofaccount-show
:twofaccountid='twofaccount.id' :twofaccountid='twofaccount.id'
:name='twofaccount.name' :service='twofaccount.service'
:icon='twofaccount.icon' :icon='twofaccount.icon'
:email='twofaccount.email'> :account='twofaccount.account'>
<one-time-password ref="OneTimePassword"></one-time-password> <one-time-password ref="OneTimePassword"></one-time-password>
</twofaccount-show> </twofaccount-show>
</modal> </modal>
@@ -48,8 +48,8 @@
response.data.forEach((data) => { response.data.forEach((data) => {
this.accounts.push({ this.accounts.push({
id : data.id, id : data.id,
name : data.name, service : data.service,
email : data.email, account : data.account,
icon : data.icon icon : data.icon
}) })
}) })
@@ -77,8 +77,8 @@
axios.get('api/twofaccounts/' + id).then(response => { axios.get('api/twofaccounts/' + id).then(response => {
this.twofaccount.id = response.data.id this.twofaccount.id = response.data.id
this.twofaccount.name = response.data.name this.twofaccount.service = response.data.service
this.twofaccount.email = response.data.email this.twofaccount.account = response.data.account
this.twofaccount.icon = response.data.icon this.twofaccount.icon = response.data.icon
this.$refs.OneTimePassword.AccountId = response.data.id this.$refs.OneTimePassword.AccountId = response.data.id

View File

@@ -20,13 +20,13 @@
<div class="field"> <div class="field">
<label class="label">Service</label> <label class="label">Service</label>
<div class="control"> <div class="control">
<input class="input" type="text" placeholder="Name" v-model="twofaccount.name" required autofocus /> <input class="input" type="text" placeholder="Service" v-model="twofaccount.service" required autofocus />
</div> </div>
</div> </div>
<div class="field"> <div class="field">
<label class="label">Email</label> <label class="label">Account</label>
<div class="control"> <div class="control">
<input class="input" type="text" placeholder="Email" v-model="twofaccount.email" /> <input class="input" type="text" placeholder="Email" v-model="twofaccount.account" />
</div> </div>
</div> </div>
<div class="field"> <div class="field">
@@ -73,8 +73,8 @@
data() { data() {
return { return {
twofaccount: { twofaccount: {
'name' : '', 'service' : '',
'email' : '', 'account' : '',
'uri' : '', 'uri' : '',
'icon' : '' 'icon' : ''
} }

View File

@@ -7,13 +7,13 @@
<div class="field"> <div class="field">
<label class="label">Service</label> <label class="label">Service</label>
<div class="control"> <div class="control">
<input class="input" type="text" placeholder="Account name" v-model="twofaccount.name" required autofocus /> <input class="input" type="text" placeholder="Service" v-model="twofaccount.service" required autofocus />
</div> </div>
</div> </div>
<div class="field"> <div class="field">
<label class="label">Email</label> <label class="label">Account</label>
<div class="control"> <div class="control">
<input class="input" type="text" placeholder="account email" v-model="twofaccount.email" /> <input class="input" type="text" placeholder="Account" v-model="twofaccount.account" />
</div> </div>
</div> </div>
<div class="field"> <div class="field">

View File

@@ -32,14 +32,14 @@ class TwoFAccountTest extends TestCase
{ {
$response = $this->actingAs($this->user, 'api') $response = $this->actingAs($this->user, 'api')
->json('POST', '/api/twofaccounts', [ ->json('POST', '/api/twofaccounts', [
'name' => 'testCreation', 'service' => 'testCreation',
'email' => 'test@example.org', 'account' => 'test@example.org',
'uri' => 'test', 'uri' => 'test',
]) ])
->assertStatus(201) ->assertStatus(201)
->assertJson([ ->assertJson([
'name' => 'testCreation', 'service' => 'testCreation',
'email' => 'test@example.org', 'account' => 'test@example.org',
'uri' => 'test', 'uri' => 'test',
]); ]);
} }
@@ -53,8 +53,8 @@ class TwoFAccountTest extends TestCase
public function testTOTPgeneration() public function testTOTPgeneration()
{ {
$twofaccount = factory(TwoFAccount::class)->create([ $twofaccount = factory(TwoFAccount::class)->create([
'name' => 'testTOTP', 'service' => 'testTOTP',
'email' => 'test@test.com', 'account' => 'test@test.com',
'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHVVRBGY7UIW&issuer=test' 'uri' => 'otpauth://totp/test@test.com?secret=A4GRFHVVRBGY7UIW&issuer=test'
]); ]);
@@ -78,15 +78,15 @@ class TwoFAccountTest extends TestCase
$response = $this->actingAs($this->user, 'api') $response = $this->actingAs($this->user, 'api')
->json('PUT', '/api/twofaccounts/' . $twofaccount->id, [ ->json('PUT', '/api/twofaccounts/' . $twofaccount->id, [
'name' => 'testUpdate', 'service' => 'testUpdate',
'email' => 'testUpdate@test.com', 'account' => 'testUpdate@test.com',
'uri' => 'testUpdate', 'uri' => 'testUpdate',
]) ])
->assertStatus(200) ->assertStatus(200)
->assertJson([ ->assertJson([
'id' => 1, 'id' => 1,
'name' => 'testUpdate', 'service' => 'testUpdate',
'email' => 'testUpdate@test.com', 'account' => 'testUpdate@test.com',
'uri' => 'testUpdate', 'uri' => 'testUpdate',
'icon' => null, 'icon' => null,
]); ]);
@@ -108,8 +108,8 @@ class TwoFAccountTest extends TestCase
->assertJsonStructure([ ->assertJsonStructure([
'*' => [ '*' => [
'id', 'id',
'name', 'service',
'email', 'account',
'uri', 'uri',
'icon', 'icon',
'created_at', 'created_at',