Skip to content

Commit 4a09519

Browse files
codercatcodercat
codercat
authored and
codercat
committed
upload
1 parent bb1d8a1 commit 4a09519

File tree

117 files changed

+10379
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+10379
-0
lines changed

app/.DS_Store

10 KB
Binary file not shown.

app/Auth/.DS_Store

10 KB
Binary file not shown.

app/Auth/Appliction/.DS_Store

6 KB
Binary file not shown.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Created by IntelliJ IDEA.
4+
* User: codercat
5+
* Date: 2018/5/7
6+
* Time: 15:23
7+
*/
8+
9+
namespace App\Auth\Appliction\Transformers;
10+
11+
12+
class AccountTransformer
13+
{
14+
15+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Created by IntelliJ IDEA.
4+
* User: codercat
5+
* Date: 2018/4/25
6+
* Time: 10:33
7+
*/
8+
9+
namespace App\Auth\Appliction\Services;
10+
11+
use App\Auth\Domain\Services\AccountRegistrationService as AccountRegistrationDomainService;
12+
13+
class AccountRegistrationService
14+
{
15+
16+
protected $accountRegisterDomainService;
17+
18+
public function __construct(AccountRegistrationDomainService $accountRegistrationDomainService)
19+
{
20+
$this->accountRegistrationDomainService = $accountRegistrationDomainService;
21+
}
22+
23+
24+
public function register(Array $AccountInfo)
25+
{
26+
$user = $this->accountRegistrationDomainService->register($AccountInfo);
27+
// dd($user);
28+
}
29+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Created by IntelliJ IDEA.
4+
* User: codercat
5+
* Date: 2018/4/26
6+
* Time: 10:07
7+
*/
8+
9+
namespace App\Auth\Appliction\Services;
10+
11+
use App\Auth\Domain\Services\AuthenticationService as AuthenticationDomainService;
12+
use \App\Auth\Domain\Model\Account\AccountRepository;
13+
use \App\Auth\Domain\Model\Account\Account;
14+
use League\Fractal\Manager;
15+
use League\Fractal\Resource\Collection;
16+
17+
class AuthenticationService {
18+
19+
protected $accountRepository;
20+
protected $authenticationDomainService;
21+
22+
public function __construct(AuthenticationDomainService $authenticationDomainService, AccountRepository $accountRepository)
23+
{
24+
$this->authenticationDomainService = $authenticationDomainService;
25+
$this->accountRepository = $accountRepository;
26+
}
27+
28+
public function authenticate($mobile, $password)
29+
{
30+
31+
$account = $this->authenticationDomainService->authenticate($mobile, $password);
32+
return [
33+
'nickname' => $account->nickname(),
34+
'mobile' => $account->mobile(),
35+
'id' => $account->identity()
36+
];
37+
38+
}
39+
}

app/Auth/Console/Kernel.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace App\Auth\Console;
4+
5+
use Illuminate\Console\Scheduling\Schedule;
6+
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
7+
8+
class Kernel extends ConsoleKernel
9+
{
10+
/**
11+
* The Artisan commands provided by your application.
12+
*
13+
* @var array
14+
*/
15+
protected $commands = [
16+
//
17+
];
18+
19+
/**
20+
* Define the application's command schedule.
21+
*
22+
* @param \Illuminate\Console\Scheduling\Schedule $schedule
23+
* @return void
24+
*/
25+
protected function schedule(Schedule $schedule)
26+
{
27+
// $schedule->command('inspire')
28+
// ->hourly();
29+
}
30+
31+
/**
32+
* Register the commands for the application.
33+
*
34+
* @return void
35+
*/
36+
protected function commands()
37+
{
38+
$this->load(__DIR__.'/Commands');
39+
40+
require base_path('routes/console.php');
41+
}
42+
}

app/Auth/Domain/.DS_Store

8 KB
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Created by IntelliJ IDEA.
4+
* User: codercat
5+
* Date: 2018/4/25
6+
* Time: 10:23
7+
*/
8+
namespace App\Auth\Domain\Common;
9+
10+
interface ObjectRepository
11+
{
12+
public function save($object);
13+
public function remove($object);
14+
public function findOneById($id);
15+
public function findAll();
16+
}

app/Auth/Domain/Exceptions/.DS_Store

6 KB
Binary file not shown.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Created by IntelliJ IDEA.
4+
* User: codercat
5+
* Date: 2018/5/5
6+
* Time: 15:49
7+
*/
8+
9+
namespace App\Auth\Domain\Exceptions;
10+
11+
12+
class DuplicateRegistrationException extends \Exception
13+
{
14+
15+
}

app/Auth/Domain/Model/.DS_Store

6 KB
Binary file not shown.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
namespace App\Auth\Domain\Model\Account;
4+
5+
use App\Auth\Domain\User;
6+
7+
8+
9+
class Account
10+
{
11+
12+
protected $id;
13+
14+
15+
protected $mobile;
16+
17+
18+
protected $password;
19+
20+
21+
protected $nickname;
22+
23+
24+
25+
public function __construct($mobile, $password, $nickname)
26+
{
27+
$this->setMobile($mobile);
28+
$this->setPassword($password);
29+
$this->setNickname($nickname);
30+
31+
}
32+
33+
public function nickname()
34+
{
35+
return $this->nickname;
36+
}
37+
38+
public function mobile()
39+
{
40+
return $this->mobile;
41+
}
42+
43+
44+
45+
public function setNickname(string $nickname)
46+
{
47+
if((null == $nickname))
48+
{
49+
throw new \Exception("昵称不能为空");
50+
}
51+
else if(strlen($nickname) > 32)
52+
{
53+
throw new \Exception("昵称超出长度");
54+
}
55+
$this->nickname = $nickname;
56+
}
57+
58+
59+
public function setPassword(string $password)
60+
{
61+
if((null == $password))
62+
{
63+
throw new \Exception("密码不能为空");
64+
}
65+
66+
67+
$this->password = $password;
68+
}
69+
70+
public function setMobile(string $mobile)
71+
{
72+
if((null == $mobile))
73+
{
74+
throw new \Exception("手机号不能为空");
75+
}
76+
else if(strlen($mobile) > 11)
77+
{
78+
throw new \Exception("手机号超出长度");
79+
}
80+
$this->mobile = $mobile;
81+
}
82+
83+
// public function changeMobile($mobile) {
84+
// $this->mobile = $mobile;
85+
// }
86+
87+
public function identity()
88+
{
89+
return $this->id;
90+
}
91+
92+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
4+
namespace App\Auth\Domain\Model\Account;
5+
use App\Auth\Domain\Common\ObjectRepository;
6+
7+
8+
interface AccountRepository extends ObjectRepository
9+
{
10+
11+
public function AccountFromAuthenticateCredential($mobile, $encryptedPassword);
12+
public function findOneByMobile($mobile);
13+
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Created by IntelliJ IDEA.
4+
* User: codercat
5+
* Date: 2018/5/5
6+
* Time: 14:26
7+
*/
8+
9+
namespace App\Auth\Domain\Model\Account;
10+
11+
12+
class Validator
13+
{
14+
// public
15+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Created by IntelliJ IDEA.
4+
* User: codercat
5+
* Date: 2018/4/26
6+
* Time: 11:36
7+
*/
8+
9+
namespace App\Auth\Domain\Services;
10+
11+
use App\Auth\Domain\Model\Account\AccountRepository;
12+
use App\Auth\Domain\Model\Account\Account;
13+
14+
class AccountRegistrationService
15+
{
16+
17+
protected $accountRepository;
18+
protected $encryptionService;
19+
20+
public function __construct(AccountRepository $accountRepository, EncryptionService $encryptionService)
21+
{
22+
$this->accountRepository = $accountRepository;
23+
$this->encryptionService = $encryptionService;
24+
}
25+
26+
public function register(Array $AccountInfo)
27+
{
28+
29+
// 如果昵称为空就把昵称设置成手机号
30+
null == $AccountInfo['nickname'] ? $nickname = $AccountInfo['mobile'] : $nickname = $AccountInfo['nickname'];
31+
32+
$encryptedPassword = $this->encryptionService->encrypt($AccountInfo['password']);
33+
$account = $this->accountRepository->findByMobile($AccountInfo['mobile']);
34+
if(null == $account) {
35+
$this->validatePassword($AccountInfo['password']);
36+
$newAccount = new Account($AccountInfo['mobile'], $encryptedPassword, $nickname);
37+
$this->accountRepository->save($newAccount);
38+
return $newAccount;
39+
}
40+
41+
throw new \Exception("手机号已经被注册");
42+
43+
}
44+
45+
protected function validatePassword($password)
46+
{
47+
if(null == $password) throw new \Exception("密码不能为空");
48+
if(strlen($password) < 6) throw new \Exception("密码不能小于6位");
49+
}
50+
51+
52+
53+
54+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Created by IntelliJ IDEA.
4+
* User: codercat
5+
* Date: 2018/4/26
6+
* Time: 10:07
7+
*/
8+
9+
namespace App\Auth\Domain\Services;
10+
11+
use App\Auth\Domain\Model\Account\AccountRepository;
12+
13+
14+
class AuthenticationService
15+
{
16+
protected $accountRepository;
17+
protected $encryptionService;
18+
19+
public function __construct(AccountRepository $accountRepository, EncryptionService $encryptionService)
20+
{
21+
$this->accountRepository = $accountRepository;
22+
$this->encryptionService = $encryptionService;
23+
}
24+
25+
public function authenticate(string $mobile, string $password)
26+
{
27+
$encryptedPassword = $this->encryptionService->encrypt($password);
28+
$account = $this->accountRepository->AccountFromAuthenticateCredential($mobile, $encryptedPassword);
29+
if ($account != null) {
30+
return $account;
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)