|
| 1 | +// src/app/login/LocalLogin.tsx |
| 2 | + |
| 3 | +import React, { useState } from 'react'; |
| 4 | +import { signIn } from 'next-auth/react'; |
| 5 | +import { Grid, GridItem } from '@patternfly/react-core/dist/dynamic/layouts/Grid'; |
| 6 | +import { Content } from '@patternfly/react-core/dist/dynamic/components/Content'; |
| 7 | +import { Form } from '@patternfly/react-core/dist/dynamic/components/Form'; |
| 8 | +import { FormGroup } from '@patternfly/react-core/dist/dynamic/components/Form'; |
| 9 | +import { TextInput } from '@patternfly/react-core/dist/dynamic/components/TextInput'; |
| 10 | +import { Button } from '@patternfly/react-core/dist/dynamic/components/Button'; |
| 11 | +import { HelperText } from '@patternfly/react-core/dist/dynamic/components/HelperText'; |
| 12 | +import { HelperTextItem } from '@patternfly/react-core/dist/dynamic/components/HelperText'; |
| 13 | +import GithubIcon from '@patternfly/react-icons/dist/dynamic/icons/github-icon'; |
| 14 | +import './githublogin.css'; |
| 15 | + |
| 16 | +const LocalLogin: React.FunctionComponent = () => { |
| 17 | + const [, setShowHelperText] = useState(false); |
| 18 | + const [username, setUsername] = useState(''); |
| 19 | + const [isValidUsername, setIsValidUsername] = useState(true); |
| 20 | + const [password, setPassword] = useState(''); |
| 21 | + const [isValidPassword, setIsValidPassword] = useState(true); |
| 22 | + |
| 23 | + const handleLogin = async (e: React.FormEvent) => { |
| 24 | + e.preventDefault(); |
| 25 | + const result = await signIn('credentials', { redirect: false, username, password }); |
| 26 | + if (result?.error) { |
| 27 | + setShowHelperText(true); |
| 28 | + setIsValidUsername(false); |
| 29 | + setIsValidPassword(false); |
| 30 | + } else { |
| 31 | + window.location.href = '/'; |
| 32 | + } |
| 33 | + }; |
| 34 | + |
| 35 | + const handleUsernameChange = (_event: React.FormEvent<HTMLInputElement>, value: string) => { |
| 36 | + setUsername(value); |
| 37 | + }; |
| 38 | + |
| 39 | + const handlePasswordChange = (_event: React.FormEvent<HTMLInputElement>, value: string) => { |
| 40 | + setPassword(value); |
| 41 | + }; |
| 42 | + |
| 43 | + const handleGitHubLogin = () => { |
| 44 | + signIn('github', { callbackUrl: '/' }); |
| 45 | + }; |
| 46 | + |
| 47 | + return ( |
| 48 | + <div className="login-page-background"> |
| 49 | + <Grid hasGutter span={12}> |
| 50 | + <GridItem span={6} className="login-container"> |
| 51 | + <Content> |
| 52 | + <Content component="p" className="sign-in-text"> |
| 53 | + Login locally with a username and password or via GitHub OAuth |
| 54 | + </Content> |
| 55 | + </Content> |
| 56 | + <Content> |
| 57 | + <Content component="p" className="description-text"> |
| 58 | + Join the novel, community-based movement to create truly open-source LLMs |
| 59 | + </Content> |
| 60 | + </Content> |
| 61 | + <div className="login-container"> |
| 62 | + <Button |
| 63 | + variant="primary" |
| 64 | + icon={<GithubIcon />} |
| 65 | + iconPosition="left" |
| 66 | + size="lg" |
| 67 | + style={{ backgroundColor: 'black', marginBottom: '1rem' }} |
| 68 | + onClick={handleGitHubLogin} |
| 69 | + > |
| 70 | + Sign in with GitHub |
| 71 | + </Button> |
| 72 | + <Form onSubmit={handleLogin}> |
| 73 | + <FormGroup label="Username" fieldId="username" className="login-label"> |
| 74 | + <TextInput |
| 75 | + value={username} |
| 76 | + onChange={handleUsernameChange} |
| 77 | + id="username" |
| 78 | + isRequired |
| 79 | + validated={isValidUsername ? 'default' : 'error'} |
| 80 | + /> |
| 81 | + {!isValidUsername && ( |
| 82 | + <HelperText> |
| 83 | + <HelperTextItem variant="error">Invalid Username</HelperTextItem> |
| 84 | + </HelperText> |
| 85 | + )} |
| 86 | + </FormGroup> |
| 87 | + <FormGroup label="Password" fieldId="password" className="login-label"> |
| 88 | + <TextInput |
| 89 | + value={password} |
| 90 | + onChange={handlePasswordChange} |
| 91 | + id="password" |
| 92 | + type="password" |
| 93 | + isRequired |
| 94 | + validated={isValidPassword ? 'default' : 'error'} |
| 95 | + /> |
| 96 | + {!isValidPassword && ( |
| 97 | + <HelperText> |
| 98 | + <HelperTextItem variant="error">Invalid password</HelperTextItem> |
| 99 | + </HelperText> |
| 100 | + )} |
| 101 | + </FormGroup> |
| 102 | + <Button type="submit" style={{ backgroundColor: 'black', color: 'white' }}> |
| 103 | + Login |
| 104 | + </Button> |
| 105 | + </Form> |
| 106 | + </div> |
| 107 | + <Content> |
| 108 | + <Content component="p" className="urls-text"> |
| 109 | + <a |
| 110 | + href="https://github.com/instructlab/" |
| 111 | + style={{ color: 'white', textDecoration: 'underline' }} |
| 112 | + target="_blank" |
| 113 | + rel="noopener noreferrer" |
| 114 | + > |
| 115 | + GitHub |
| 116 | + </a>{' '} |
| 117 | + |{' '} |
| 118 | + <a |
| 119 | + href="https://github.com/instructlab/community/blob/main/Collaboration.md" |
| 120 | + style={{ color: 'white', textDecoration: 'underline' }} |
| 121 | + target="_blank" |
| 122 | + rel="noopener noreferrer" |
| 123 | + > |
| 124 | + Collaborate |
| 125 | + </a>{' '} |
| 126 | + |{' '} |
| 127 | + <a |
| 128 | + href="https://github.com/instructlab/community/blob/main/CODE_OF_CONDUCT.md" |
| 129 | + style={{ color: 'white', textDecoration: 'underline' }} |
| 130 | + target="_blank" |
| 131 | + rel="noopener noreferrer" |
| 132 | + > |
| 133 | + Code Of Conduct |
| 134 | + </a> |
| 135 | + </Content> |
| 136 | + <Content component="p" className="urls-text-medium"> |
| 137 | + <a |
| 138 | + href="https://www.redhat.com/en/about/terms-use" |
| 139 | + style={{ color: 'white', textDecoration: 'underline' }} |
| 140 | + target="_blank" |
| 141 | + rel="noopener noreferrer" |
| 142 | + > |
| 143 | + Terms of use |
| 144 | + </a>{' '} |
| 145 | + |{' '} |
| 146 | + <a |
| 147 | + href="https://www.redhat.com/en/about/privacy-policy" |
| 148 | + style={{ color: 'white', textDecoration: 'underline' }} |
| 149 | + target="_blank" |
| 150 | + rel="noopener noreferrer" |
| 151 | + > |
| 152 | + Privacy Policy |
| 153 | + </a> |
| 154 | + </Content> |
| 155 | + </Content> |
| 156 | + </GridItem> |
| 157 | + </Grid> |
| 158 | + </div> |
| 159 | + ); |
| 160 | +}; |
| 161 | + |
| 162 | +export default LocalLogin; |
0 commit comments