mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
update username
This commit is contained in:
@@ -83,6 +83,10 @@ const registerUser = async (e: Event) => {
|
||||
export const index = () => {
|
||||
const form = <HTMLFontElement>document.getElementById('form');
|
||||
form.addEventListener('submit', registerUser, true);
|
||||
usernameElement.addEventListener('input', userExists, false);
|
||||
usernameElement.addEventListener(
|
||||
'input',
|
||||
async () => await userExists(),
|
||||
false,
|
||||
);
|
||||
registerShowPassword();
|
||||
};
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import fetchMock from 'jest-fetch-mock';
|
||||
|
||||
import userExists from './userExists';
|
||||
@@ -39,6 +38,10 @@ it('finds exchange', async () => {
|
||||
usernameField.value = 'test';
|
||||
expect(await userExists()).toBe(true);
|
||||
|
||||
usernameField.value = 'test';
|
||||
fetchMock.mockResponseOnce(JSON.stringify({exists: true}));
|
||||
expect(await userExists(usernameField)).toBe(true);
|
||||
|
||||
fetchMock.mockResponseOnce(JSON.stringify({exists: false}));
|
||||
expect(await userExists()).toBe(false);
|
||||
});
|
||||
|
||||
@@ -20,8 +20,14 @@ import ROUTES from '../../../api/v1/routes';
|
||||
import genJsonPayload from '../../../utils/genJsonPayload';
|
||||
import createError from '../../../components/error/index';
|
||||
|
||||
const userExists = async () => {
|
||||
const username = <HTMLInputElement>document.getElementById('username');
|
||||
const userExists = async (element?: HTMLInputElement) => {
|
||||
console.log(element);
|
||||
let username;
|
||||
if (element === undefined) {
|
||||
username = <HTMLInputElement>document.getElementById('username');
|
||||
} else {
|
||||
username = element;
|
||||
}
|
||||
const val = username.value;
|
||||
const payload = {
|
||||
val,
|
||||
|
||||
Reference in New Issue
Block a user