Commit f506fe2b by Ivan

fix: fix signup

parent 235928c3
class UsersController < ApplicationController
allow_unauthenticated_access only: %i[ new create ]
def new
render inertia: "users/New", props: {
flash: flash.to_h
}
end
def create
@user = User.new(user_params)
if @user.save
# Automatically log in the user after registration
start_new_session_for @user
redirect_to after_authentication_url, notice: "Welcome! Your account has been created successfully."
else
render inertia: "users/New", props: {
errors: @user.errors.as_json,
flash: flash.to_h
}
end
end
private
def user_params
params.require(:user).permit(:name, :email_address, :password, :password_confirmation)
end
end
......@@ -60,7 +60,7 @@ export default function SessionsNew({ flash }) {
</Form.Control>
{errors.email_address && (
<Form.Message className="text-sm text-red-600">
{errors.email_address}
{Array.isArray(errors.email_address) ? errors.email_address[0] : errors.email_address}
</Form.Message>
)}
</Form.Field>
......@@ -83,7 +83,7 @@ export default function SessionsNew({ flash }) {
</Form.Control>
{errors.password && (
<Form.Message className="text-sm text-red-600">
{errors.password}
{Array.isArray(errors.password) ? errors.password[0] : errors.password}
</Form.Message>
)}
</Form.Field>
......
import { useState } from 'react'
import { Head, Link, useForm , router } from '@inertiajs/react'
import * as Form from '@radix-ui/react-form'
import ErrorMessage from '../../components/ErrorMessage'
export default function UsersNew({ flash, errors = {} }) {
const { data, setData, processing } = useForm({
name: '',
email_address: '',
password: '',
password_confirmation: '',
})
const handleSubmit = (e) => {
e.preventDefault()
router.post('/users', { user: data })
}
return (
<div className="min-h-screen flex flex-col justify-center py-12 sm:px-6 lg:px-8 bg-gray-50">
<Head title="Sign up" />
<div className="sm:mx-auto sm:w-full sm:max-w-md">
<h2 className="mt-6 text-center text-3xl font-extrabold text-gray-900">
Create a new account
</h2>
<p className="mt-2 text-center text-sm text-gray-600">
Or{' '}
<Link
href="/session/new"
className="font-medium text-indigo-600 hover:text-indigo-500"
>
log in to your account
</Link>
</p>
</div>
<div className="mt-8 sm:mx-auto sm:w-full sm:max-w-md">
<div className="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10">
{flash?.alert && (
<div className="mb-4">
<ErrorMessage message={flash.alert} />
</div>
)}
<Form.Root className="space-y-6" onSubmit={handleSubmit}>
<Form.Field name="name" className="space-y-1">
<Form.Label className="block text-sm font-medium text-gray-700">
Full name
</Form.Label>
<Form.Control asChild>
<input
id="name"
name="name"
type="text"
autoComplete="name"
required
value={data.name}
onChange={(e) => setData('name', e.target.value)}
className="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
/>
</Form.Control>
{errors.name && (
<Form.Message className="text-sm text-red-600">
{errors.name}
</Form.Message>
)}
</Form.Field>
<Form.Field name="email_address" className="space-y-1">
<Form.Label className="block text-sm font-medium text-gray-700">
Email address
</Form.Label>
<Form.Control asChild>
<input
id="email_address"
name="email_address"
type="email"
autoComplete="email"
required
value={data.email_address}
onChange={(e) => setData('email_address', e.target.value)}
className="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
/>
</Form.Control>
{errors.email_address && (
<Form.Message className="text-sm text-red-600">
{errors.email_address}
</Form.Message>
)}
</Form.Field>
<Form.Field name="password" className="space-y-1">
<Form.Label className="block text-sm font-medium text-gray-700">
Password
</Form.Label>
<Form.Control asChild>
<input
id="password"
name="password"
type="password"
autoComplete="new-password"
required
value={data.password}
onChange={(e) => setData('password', e.target.value)}
className="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
/>
</Form.Control>
{errors.password && (
<Form.Message className="text-sm text-red-600">
{errors.password}
</Form.Message>
)}
</Form.Field>
<Form.Field name="password_confirmation" className="space-y-1">
<Form.Label className="block text-sm font-medium text-gray-700">
Confirm password
</Form.Label>
<Form.Control asChild>
<input
id="password_confirmation"
name="password_confirmation"
type="password"
autoComplete="new-password"
required
value={data.password_confirmation}
onChange={(e) => setData('password_confirmation', e.target.value)}
className="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
/>
</Form.Control>
{errors.password_confirmation && (
<Form.Message className="text-sm text-red-600">
{errors.password_confirmation}
</Form.Message>
)}
</Form.Field>
<div>
<Form.Submit asChild>
<button
type="submit"
disabled={processing}
className="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 disabled:opacity-50"
>
{processing ? 'Creating account...' : 'Sign up'}
</button>
</Form.Submit>
</div>
</Form.Root>
<div className="mt-6">
<div className="relative">
<div className="absolute inset-0 flex items-center">
<div className="w-full border-t border-gray-300" />
</div>
<div className="relative flex justify-center text-sm">
<span className="px-2 bg-white text-gray-500">
Or continue with
</span>
</div>
</div>
<div className="mt-6 grid grid-cols-1 gap-3">
<button
type="button"
disabled
title="GitHub registration is not available yet"
className="w-full inline-flex justify-center py-2 px-4 border border-gray-300 rounded-md shadow-sm bg-white text-sm font-medium text-gray-400 opacity-60 cursor-not-allowed"
>
<svg className="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 20 20" aria-hidden="true">
<path
fillRule="evenodd"
d="M10 0C4.477 0 0 4.484 0 10.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0110 4.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.203 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.942.359.31.678.921.678 1.856 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0020 10.017C20 4.484 15.522 0 10 0z"
clipRule="evenodd"
/>
</svg>
<span>GitHub</span>
</button>
</div>
</div>
</div>
</div>
</div>
)
}
class AddNameToUsers < ActiveRecord::Migration[8.0]
def change
add_column :users, :name, :string
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2025_03_08_054000) do
ActiveRecord::Schema[8.0].define(version: 2025_03_08_064523) do
create_table "image_tags", force: :cascade do |t|
t.integer "image_id", null: false
t.integer "tag_id", null: false
......@@ -49,6 +49,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_03_08_054000) do
t.string "password_digest", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name"
t.index ["email_address"], name: "index_users_on_email_address", unique: true
end
......
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