Commit f0185086 authored by UtopiaXC's avatar UtopiaXC

🚗 完成注册

parent a1eecf4b
......@@ -3,7 +3,12 @@
namespace App\Http\Controllers;
use App\Http\Utils\R;
use App\Models\Users\User;
use App\Models\Users\UserProfile;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Webpatser\Uuid\Uuid;
class UserController extends Controller
{
......@@ -12,8 +17,35 @@ class UserController extends Controller
if (!CaptchaController::check_captcha($request->get("captcha"), $request->cookie(app()->getNamespace() . "session"))) {
return R::error("403001","验证码错误");
}
try {
$email = $request->get("email");
$user_name=$request->get("user_name");
$password=password_hash($request->get("password"),PASSWORD_DEFAULT);
$user=User::query()
->where("user_name",$user_name)
->orWhere("user_name",$email)
->get();
if (sizeof($user)!=0){
return R::error("403002","该邮箱或用户名已被注册");
}
$user=new User();
$user->id=Uuid::generate();
$user->user_name=$user_name;
$user->user_email=$email;
$user->user_password=$password;
$user->user_type=\UserTypeEnum::NORMAL;
$user->user_status=\UserStatusEnum::NOT_VERITY;
$user_profile=new UserProfile();
$user_profile->id=Uuid::generate();
$user_profile->user_id=$user->id;
DB::beginTransaction();
$user->save();
$user_profile->save();
DB::commit();
}catch (Exception $e){
DB::rollBack();
return R::error("500001","用户数据保存错误");
}
return R::ok();
}
......
......@@ -8,4 +8,7 @@ use Illuminate\Database\Eloquent\Model;
class UserProfile extends Model
{
use HasFactory;
protected $table="users_profile";
public $incrementing = false;
protected $keyType = 'string';
}
......@@ -23,3 +23,16 @@ class Middleware
{
const AUTH_MIDDLEWARE = 'AuthMiddleWare';
}
class UserTypeEnum{
const ADMIN="01";
const NORMAL="02";
const VIP="03";
}
class UserStatusEnum{
const NOT_VERITY="01";
const NORMAL="02";
const BANNED="03";
const BANNED_FOREVER="04";
}
......@@ -16,14 +16,14 @@ class CreateUsersProfile extends Migration
Schema::create('users_profile', function (Blueprint $table) {
$table->uuid('id');
$table->string('user_id');
$table->string('user_nickname');
$table->string('user_avatar');
$table->string('user_sex');
$table->date('user_birthday');
$table->string('user_job');
$table->string('user_city');
$table->string('user_main_page');
$table->string('user_github');
$table->string('user_nickname')->nullable();;
$table->string('user_avatar')->nullable();;
$table->string('user_sex')->nullable();;
$table->date('user_birthday')->nullable();;
$table->string('user_job')->nullable();;
$table->string('user_city')->nullable();;
$table->string('user_main_page')->nullable();;
$table->string('user_github')->nullable();;
$table->timestamps();
});
}
......
......@@ -18,9 +18,9 @@
<form>
<div class="mb-3">
<div class="form-floating">
<input type="email" class="form-control" id="email"
placeholder="name@example.com">
<label for="email">邮箱</label>
<input type="text" class="form-control" id="email"
placeholder="邮箱或用户名">
<label for="email">邮箱或用户名</label>
</div>
</div>
<div class="mb-3">
......@@ -31,8 +31,8 @@
</div>
</div>
<div class="d-grid">
<button class="btn btn-info m-b-xs">登录</button>
<button class="btn btn-primary" onclick="window.open('{{WebUrl::FIND_PASSWORD}}')">
<button type="button" onclick="doLogin()" class="btn btn-info m-b-xs">登录</button>
<button type="button" class="btn btn-primary" onclick="window.location.href='{{WebUrl::FIND_PASSWORD}}'">
找回密码
</button>
</div>
......@@ -45,13 +45,49 @@
</div>
</div>
</div>
<div class="modal fade" id="alert" tabindex="-1" aria-labelledby="alert" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="alert_title"></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="alert_content"></div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-bs-dismiss="modal">确认</button>
</div>
</div>
</div>
</div>
</body>
@endsection
@section('script')
<script>
function logon(){
function doLogin(){
let email=$("#email").val()
let password=$("#password").val()
if (email===""||password===""){
showAlert("警告","您有未输入的部分")
return
}
let pattern = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
if (!pattern.test(email)) {
showAlert("警告", "邮箱格式错误")
return
}
$.ajax({
})
}
function showAlert(title, content) {
let alert = $("#alert")
let title_elem = $("#alert_title")
let content_elem = $("#alert_content")
title_elem.html(title)
content_elem.html(content)
alert.modal('show')
}
</script>
@endsection
......@@ -85,7 +85,7 @@
<div class="modal-body">请前往登录,并查看自己的邮箱进行激活(可能在垃圾邮件中)</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary"
{{-- onclick="window.location.href='{{WebUrl::LOGIN}}'" --}}
onclick="window.location.href='{{WebUrl::LOGIN}}'"
data-bs-dismiss="modal">确认</button>
</div>
</div>
......
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 to comment