Commit b5bd661c by 肖康

Merge branch 'dev/ver/1.0.0' of http://git.ichunt.net/semour/semour_web into dev/ver/1.0.0

parents 0ce44bf7 c2b27150
......@@ -2,13 +2,8 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="fb90add0-1393-48c2-9f26-72365d42cd03" name="变更" comment="">
<change beforePath="$PROJECT_DIR$/.env" beforeDir="false" afterPath="$PROJECT_DIR$/.env" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Controllers/Api/AuthApiController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/Api/AuthApiController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Controllers/Controller.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/Controller.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Kernel.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Kernel.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/database.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/database.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/routes/api.php" beforeDir="false" afterPath="$PROJECT_DIR$/routes/api.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Controllers/SkuController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/SkuController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/routes/web.php" beforeDir="false" afterPath="$PROJECT_DIR$/routes/web.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/storage/app/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/app/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/storage/app/public/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/app/public/.gitignore" afterDir="false" />
......@@ -154,18 +149,18 @@
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/app/Http" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/app/Http/Controllers" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_package_manager_path" value="npm" />
<property name="vue.rearranger.settings.migration" value="true" />
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http\Controllers" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http\Services" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http\Requests" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http\Controllers\Api" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\resources\views\about" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http\Traits" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http\Api" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Exceptions" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\resources\views\home" />
......@@ -188,7 +183,7 @@
<updated>1666170258203</updated>
<workItem from="1666170260162" duration="17108000" />
<workItem from="1666835076791" duration="693000" />
<workItem from="1667266026118" duration="8640000" />
<workItem from="1667266026118" duration="20780000" />
</task>
<servers />
</component>
......
<?php
namespace App\Exceptions;
use App\Http\ApiHelper\Response;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
/*
*无效请求异常
*/
class InvalidRequestException extends \Exception
{
public $field;
public function __construct($message, $field, $code = 200)
{
$this->field = $field;
parent::__construct($message, $code);
}
public function render(Request $request)
{
$request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
$path_info = parse_url($request_uri);
$err_info = [
'domain' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '',
'interface' => isset($path_info) ? $path_info['path'] : '',
'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '',
'ip' => request()->getClientIp(),
'time' => time(),
'other' => '',
'request_params' => $_REQUEST,
'msg' => $this->getMessage(),
"code" => $this->getCode(),
];
Log::error(json_encode($err_info, JSON_UNESCAPED_UNICODE));
if ($this->field) {
return response()->json(json_decode(Response::setErrorWithField($this->message, $this->field), true));
} else {
return response()->json(json_decode(Response::setError($this->message), true));
}
}
}
......@@ -17,9 +17,15 @@ class Response
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
public static function setErrorWithField($errMsg, $field, $errCode = ApiCode::API_CODE_ERROR, $data = [])
{
return json_encode(['code' => $errCode, 'msg' => $errMsg, 'field' => $field, 'data' => $data],
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
public static function setSuccess($data, $code = ApiCode::API_CODE_SUCCESS, $msg = "")
{
return json_encode(['code' => $code, 'msg' => $msg, 'data' => $data],
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
}
\ No newline at end of file
}
......@@ -2,6 +2,7 @@
namespace App\Http\Controllers\Api;
use App\Http\Requests\UserRegister;
use App\Models\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Foundation\Auth\ThrottlesLogins;
......@@ -17,19 +18,19 @@ class AuthApiController extends Controller
use ThrottlesLogins, RegistersUsers;
public function register(Request $request)
public function register(UserRegister $request)
{
$validator = Validator::make($request->all(), [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
], [
'password.confirmed' => 'Passwords do not match!',
]);
if ($validator->fails()) {
return $this->setError($validator->errors()->first());
$email = $request->input('email');
if (User::where('email', $email)->exists()) {
return $this->setError('Email has been taken');
}
//判断邮箱验证码
$redisKey = 'sem_email_code_register_' . $email;
$cachedEmailCode = Redis::get($redisKey);
if ($cachedEmailCode != $request->input('email_code')) {
return $this->setError('Email code invalid');
}
$user = User::createUser($request->all());
\Auth::login($user);
......@@ -73,6 +74,7 @@ class AuthApiController extends Controller
public function resetPassword(Request $request)
{
$validator = Validator::make($request->all(), [
'old_password' => 'required|min:8',
'password' => ['required', 'string', 'min:8', 'confirmed'],
......@@ -85,15 +87,15 @@ class AuthApiController extends Controller
if ($validator->fails()) {
return $this->setError($validator->errors()->first());
}
$password = $request->get('password');
$match = User::where('password', Hash::make($request->get('old_password')))->exists();
if (!$match) {
$oldPassword = $request->get('old_password');
$userId = Auth::user()->id;
$hashedPassword = User::where('id', $userId)->value('password');
if (!Hash::check($oldPassword, $hashedPassword)) {
return $this->setError('Wrong Password!');
}
$user = new User();
$user = User::find($userId);
$user->password = Hash::make($password);
$user->update_time = time();
$result = $user->save();
......@@ -113,14 +115,17 @@ class AuthApiController extends Controller
return $this->setError('Email address required');
}
$info = User::where('email', $email)->first();
if ($info) {
if ($info && $type == 'register') {
return $this->setError('This email had been registered');
}
//发送验证码
$code = mt_rand(1000, 9999);
$redisKey = 'sem_email_code_' . $type;
Redis::hset($redisKey, $code);
$redisKey = 'sem_email_code_' . $type . '_' . $email;
if (Redis::get($redisKey)) {
return $this->setError('Email code had been sent');
}
Redis::set($redisKey, $code);
Redis::expire($redisKey, 60);
$subject = config('mail.from.name');
$msg = 'Email Code:' . $code . '.';
......
<?php
namespace App\Http\Controllers\Api;
use App\Http\Requests\InquirySave;
use App\Http\Services\InquiryService;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class InquiryApiController extends Controller
{
public function add(InquirySave $request)
{
$data = $request->only([
'items',
'data',
]);
$user = request()->user();
$result = InquiryService::addInquiry($data, $user);
if (!$result) {
return $this->setError('Add inquiry failed , please contact administrator');
}
return $this->setSuccess('Add inquiry success');
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ClassificationController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
// $this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('classification.index');
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
//询价
class InquiryController extends Controller
{
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class MallController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
// $this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('mall.index');
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class SearchController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
// $this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('search.index');
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
//询价
class SkuController extends Controller
{
public function detail()
{
return view('sku.detail');
}
}
......@@ -22,7 +22,8 @@ class CheckApiLogin
'msg' => 'need login...',
];
return response()->json($response);
}else{
} else {
$request->user = \Auth::user();
return $next($request);
}
}
......
<?php
namespace App\Http\Requests;
use App\Exceptions\InvalidRequestException;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;
class BaseRequest extends FormRequest
{
protected function failedValidation(Validator $validator)
{
$errors = $validator->errors();
$firstError = $errors->first();
$fields = $errors->keys();
\Log::channel("formRequest")->info(
sprintf(
"错误:请求参数 %s,错误原因:%s",
print_r(request()->all(), true),
json_encode($errors->all(), JSON_UNESCAPED_UNICODE)
)
);
throw new InvalidRequestException($firstError, $fields[0]);
}
public function authorize()
{
return true;
}
public function validated()
{
return $this->validator->validated();
}
public function __get($key)
{
if ($key == 'user') {
return request()->get('user');
}
if ($key == 'perms') {
return request()->get('perms');
}
}
}
<?php
namespace App\Http\Requests;
class InquirySave extends BaseRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'items' => 'required',
'items.*.goods_name' => 'required|string|max:100',
'items.*.brand_name' => 'required|string|max:100',
'items.*.inquiry_number' => 'required|integer',
'remark' => 'max:255|required',
];
}
}
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UserRegister extends BaseRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
[
'email' => 'required|string|email|max:100',
'password' => 'required|string|min:8|confirmed',
'first_name' => 'required|max:100',
'last_name' => 'required|max:100',
'email_code' => 'required|max:100',
'phone' => 'required|max:100',
'company_name' => 'required|max:100',
]
];
}
public function messages()
{
return [
'password.confirmed' => 'Passwords do not match!',
];
}
}
<?php
namespace App\Http\Services;
class AuthService
{
}
<?php
namespace App\Http\Services;
class ClassService
{
}
<?php
namespace App\Http\Services;
use App\Models\Inquiry;
use App\Models\InquiryItems;
use Illuminate\Support\Facades\DB;
class InquiryService
{
public static function addInquiry($data, $user)
{
return DB::transaction(function () use ($data, $user) {
$items = \Arr::get($data, 'item', []);
$remark = $data['remark'];
$inquiry = [
'user_id' => $user->user_id,
'user_types' => $user->account_properties,
'remark' => $remark,
'create_time' => time(),
];
$inquiryId = Inquiry::addInquiry($inquiry);
$inquiryItems = [];
foreach ($items as $item) {
$inquiryItems[] = [
'inquiry_id' => $inquiryId,
'goods_name' => $item['goods_name'],
'brand_name' => $item['brand_name'],
'inquiry_number' => $item['inquiry_number'],
'remark' => $remark,
'create_time' => $item['create_time'],
];
}
return InquiryItems::addInquiryItems($inquiryItems);
});
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Inquiry extends Model
{
//
public $timestamps = false;
public static function addInquiry($inquiry)
{
return self::insertGetId($inquiry);
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class InquiryItems extends Model
{
public $timestamps = false;
public static function addInquiryItems($inquiryItems = [])
{
return self::insert($inquiryItems);
}
}
......@@ -46,8 +46,11 @@ class User extends Authenticatable implements MustVerifyEmail
public static function createUser($data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'phone' => $data['phone'],
'email_verified_at' => now(),
'company_name' => $data['company_name'],
'password' => Hash::make($data['password']),
]);
}
......
......@@ -123,7 +123,7 @@ return [
'options' => [
'cluster' => env('REDIS_CLUSTER', 'redis'),
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
'prefix' => env('REDIS_PREFIX', ''),
],
'default' => [
......
......@@ -15,15 +15,15 @@ use Illuminate\Support\Facades\Route;
*/
Route::middleware(['api'])->namespace('Api')->group(function () {
Route::ANY('/user/login', 'AuthApiController@login');
Route::POST('/user/register', 'AuthApiController@register');
Route::POST('/auth/login', 'AuthApiController@login');
Route::POST('/auth/register', 'AuthApiController@register');
});
Route::middleware(['api','api.check'])->namespace('Api')->group(function () {
Route::GET('/user/logout', 'AuthApiController@logout');
Route::middleware(['api', 'api.check'])->namespace('Api')->group(function () {
Route::GET('/auth/logout', 'AuthApiController@logout');
Route::POST('auth/reset_password', 'AuthApiController@resetPassword');
Route::POST('auth/send_email_code', 'AuthApiController@sendEmailCode');
Route::ANY('inquiry/add', 'InquiryApiController@add');
});
Route::middleware(['api','api.check'])->namespace('Auth')->group(function () {
Route::Any('user/reset_password', 'ResetPasswordController@reset');
});
......@@ -37,3 +37,4 @@ Route::get('/about/privacy', 'AboutController@privacy')->name('about.privacy');
Route::get('/about/term', 'AboutController@term')->name('about.term');
Route::get('/about/termuser', 'AboutController@termuser')->name('about.termuser');
Route::get('/about/refund', 'AboutController@refund')->name('about.refund');
Route::get('/mall/index', 'MallController@index')->name('mall.index');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment