forked from OpenWF/SpaceNinjaServer
		
	fix(webui): handle name already being taken (#2530)
Closes #2528 Reviewed-on: OpenWF/SpaceNinjaServer#2530 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									ddf3cd49b5
								
							
						
					
					
						commit
						304af514e2
					
				@ -2,7 +2,13 @@ import http from "http";
 | 
				
			|||||||
import https from "https";
 | 
					import https from "https";
 | 
				
			||||||
import ws from "ws";
 | 
					import ws from "ws";
 | 
				
			||||||
import { Account } from "@/src/models/loginModel";
 | 
					import { Account } from "@/src/models/loginModel";
 | 
				
			||||||
import { createAccount, createNonce, getUsernameFromEmail, isCorrectPassword } from "@/src/services/loginService";
 | 
					import {
 | 
				
			||||||
 | 
					    createAccount,
 | 
				
			||||||
 | 
					    createNonce,
 | 
				
			||||||
 | 
					    getUsernameFromEmail,
 | 
				
			||||||
 | 
					    isCorrectPassword,
 | 
				
			||||||
 | 
					    isNameTaken
 | 
				
			||||||
 | 
					} from "@/src/services/loginService";
 | 
				
			||||||
import { IDatabaseAccountJson } from "@/src/types/loginTypes";
 | 
					import { IDatabaseAccountJson } from "@/src/types/loginTypes";
 | 
				
			||||||
import { HydratedDocument } from "mongoose";
 | 
					import { HydratedDocument } from "mongoose";
 | 
				
			||||||
import { logError } from "@/src/utils/logger";
 | 
					import { logError } from "@/src/utils/logger";
 | 
				
			||||||
@ -105,14 +111,16 @@ const wsOnConnect = (ws: ws, req: http.IncomingMessage): void => {
 | 
				
			|||||||
                    }
 | 
					                    }
 | 
				
			||||||
                } else if (data.auth.isRegister) {
 | 
					                } else if (data.auth.isRegister) {
 | 
				
			||||||
                    const name = await getUsernameFromEmail(data.auth.email);
 | 
					                    const name = await getUsernameFromEmail(data.auth.email);
 | 
				
			||||||
                    account = await createAccount({
 | 
					                    if (!(await isNameTaken(name))) {
 | 
				
			||||||
                        email: data.auth.email,
 | 
					                        account = await createAccount({
 | 
				
			||||||
                        password: data.auth.password,
 | 
					                            email: data.auth.email,
 | 
				
			||||||
                        ClientType: "webui",
 | 
					                            password: data.auth.password,
 | 
				
			||||||
                        LastLogin: new Date(),
 | 
					                            ClientType: "webui",
 | 
				
			||||||
                        DisplayName: name,
 | 
					                            LastLogin: new Date(),
 | 
				
			||||||
                        Nonce: createNonce()
 | 
					                            DisplayName: name,
 | 
				
			||||||
                    });
 | 
					                            Nonce: createNonce()
 | 
				
			||||||
 | 
					                        });
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                if (account) {
 | 
					                if (account) {
 | 
				
			||||||
                    (ws as IWsCustomData).accountId = account.id;
 | 
					                    (ws as IWsCustomData).accountId = account.id;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user