Commit fcc22723 by 杨树贤

修改用户信息相关接口

parent ab5dd96d
......@@ -4,18 +4,7 @@
<list default="true" id="fb90add0-1393-48c2-9f26-72365d42cd03" name="变更" comment="">
<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/Api/InquiryApiController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/Api/InquiryApiController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Controllers/Auth/RegisterController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/Auth/RegisterController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Services/InquiryService.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Services/InquiryService.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Models/Inquiry.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/InquiryModel.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Models/InquiryItems.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/InquiryItemsModel.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Models/User.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/UserModel.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Models/UserAddress.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/UserAddressModel.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/auth.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/auth.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/field.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/field.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/database/factories/UserAddressFactory.php" beforeDir="false" afterPath="$PROJECT_DIR$/database/factories/UserAddressFactory.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/database/factories/UserFactory.php" beforeDir="false" afterPath="$PROJECT_DIR$/database/factories/UserFactory.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/database/seeds/UserAddressSeeder.php" beforeDir="false" afterPath="$PROJECT_DIR$/database/seeds/UserAddressSeeder.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/routes/api.php" beforeDir="false" afterPath="$PROJECT_DIR$/routes/api.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" />
......@@ -161,18 +150,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$/resources/views" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/app/Http/Controllers/Api" />
<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\Controllers\Api" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\resources\views" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\resources\views\sku" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\resources\views\mall" />
<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" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\resources\views\home" />
......@@ -195,7 +184,7 @@
<updated>1666170258203</updated>
<workItem from="1666170260162" duration="17108000" />
<workItem from="1666835076791" duration="693000" />
<workItem from="1667266026118" duration="25211000" />
<workItem from="1667266026118" duration="31053000" />
</task>
<servers />
</component>
......
......@@ -111,8 +111,12 @@ class AuthApiController extends Controller
{
$email = $request->input('email');
$type = $request->input('type', 'register');
if (!$email) {
return $this->setError('Email address required');
$validator = Validator::make($request->all(), [
'email' => 'required|email',
]);
if ($validator->fails()) {
return $this->setError($validator->errors()->first());
}
$info = UserModel::where('email', $email)->first();
if ($info && $type == 'register') {
......
<?php
namespace App\Http\Controllers\Api;
use App\Models\UserModel;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Validator;
class UserApiController extends Controller
{
public function info(Request $request)
{
$user = $request->user();
$user = \Arr::only($user->toArray(), [
'id',
'name',
'email',
'phone',
'account_properties',
'company_name',
'first_name',
'last_name',
]);
return $this->setSuccessData($user);
}
public function update(Request $request)
{
$data = $request->only([
'account_properties',
'company_name',
'first_name',
'last_name',
]);
$id = $request->user->id;
$data['update_time'] = time();
$result = UserModel::where('id', $id)->update($data);
if (!$result) {
return $this->setError('Save user info failed');
}
return $this->setSuccess('Save user info success');
}
public function changePhone(Request $request)
{
$password = $request->input('password');
$phone = $request->input('phone');
$validator = Validator::make($request->all(), [
'phone' => 'required',
'password' => 'required|max:100'
]);
if ($validator->fails()) {
return $this->setError($validator->errors()->first());
}
$userId = Auth::user()->id;
$hashedPassword = UserModel::where('id', $userId)->value('password');
if (!Hash::check($password, $hashedPassword)) {
return $this->setError('Wrong Password!');
}
$result = UserModel::where('id', $userId)->update(['phone' => $phone]);
if (!$result) {
return $this->setError('Change phone failed');
}
return $this->setSuccess('Change phone success');
}
public function changeEmail(Request $request)
{
$password = $request->input('password');
$email = $request->input('email');
$validator = Validator::make($request->all(), [
'email' => 'required|email',
'password' => 'required|max:100'
]);
if ($validator->fails()) {
return $this->setError($validator->errors()->first());
}
$userId = Auth::user()->id;
$hashedPassword = UserModel::where('id', $userId)->value('password');
if (!Hash::check($password, $hashedPassword)) {
return $this->setError('Wrong Password!');
}
//发送邮箱验证码
$redisKey = 'sem_email_code_change_email' . '_' . $email;
$cachedEmailCode = Redis::get($redisKey);
if ($cachedEmailCode != $request->input('email_code')) {
return $this->setError('Email code invalid');
}
$result = UserModel::where('id', $userId)->update(['email' => $email]);
if (!$result) {
return $this->setError('Change email failed');
}
return $this->setSuccess('Change email success');
}
}
......@@ -37,8 +37,17 @@ class InquiryService
public static function getInquiryDetail($inquiryId)
{
$inquiry = InquiryModel::where('inquiry_id', $inquiryId)->first()->toArray();
$inquiryItems = InquiryItemsModel::where('inquiry_id', $inquiryId)->get()->toArray();
$inquiry = InquiryModel::select([
'inquiry_id',
'inquiry_sn',
'status',
'remark',
])->where('inquiry_id', $inquiryId)->first()->toArray();
$inquiryItems = InquiryItemsModel::select([
'goods_name',
'brand_name',
'inquiry_number',
])->where('inquiry_id', $inquiryId)->get()->toArray();
$inquiry['items'] = $inquiryItems;
return $inquiry;
}
......
......@@ -26,6 +26,8 @@ Route::middleware(['api', 'api.check'])->namespace('Api')->group(function () {
Route::POST('auth/reset_password', 'AuthApiController@resetPassword');
Route::POST('auth/send_email_code', 'AuthApiController@sendEmailCode');
Route::get('user/info', 'UserApiController@info');
Route::ANY('inquiry/add', 'InquiryApiController@add');
Route::ANY('inquiry/list', 'InquiryApiController@list');
Route::ANY('inquiry/detail', 'InquiryApiController@detail');
......
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