Skip to content

Commit

Permalink
Revert "Clan test might not work"
Browse files Browse the repository at this point in the history
This reverts commit 8983a36.
  • Loading branch information
YoctoProductions committed Feb 14, 2025
1 parent 8cc1bc5 commit 1ec34f4
Show file tree
Hide file tree
Showing 11 changed files with 6 additions and 112 deletions.
18 changes: 0 additions & 18 deletions api/src/accounts/accounts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { FindOneOptions, Repository } from 'typeorm';
import { Account } from './account.entity';
import * as config from '../config';
import validateUsername from 'src/helpers/validateUsername';
import validateClan from 'src/helpers/validateClan';
import { Transaction } from 'src/transactions/transactions.entity';
import * as cosmetics from '../cosmetics.json';
import CacheObj from 'src/Cache';
Expand Down Expand Up @@ -276,23 +275,6 @@ export class AccountsService {
}
}

async changeClan(id: number, clan: string) {
// validate clan
if(validateClan(clan)) {
return {error: validateClan(clan)};
}
const account = await this.getById(id);

account.clan = clan;
account.lastClanChange = new Date();
try {
await this.accountsRepository.save(account);
return {success: true};
} catch(e) {
return {error: 'Failed to update clan, '+ e.message};
}
}

async update(id: number, updates: Partial<Account>) {
const account = await this.accountsRepository.findOneBy({ id });
if (!account) {
Expand Down
5 changes: 0 additions & 5 deletions api/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ export class AuthController {
let result = await this.authService.changeUsername(request.account, request.body.newUsername);
return result;
}
@Post('change-clan')
async changeClan(@Req() request) {
let result = await this.authService.changeClan(request.account, request.body.newClan);
return result;
}

setCookie(res: Response, key: string, value: string) {
return res.cookie(key, value, {
Expand Down
16 changes: 2 additions & 14 deletions api/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class AuthService {
try {
account = await this.accountsService.findOne({ where: { secret: data.secret } });
} catch (e) {
throw new UnauthorizedException('User does not exist');
throw new UnauthorizedException('User does not exists');
}

return { account: this.accountsService.sanitizeAccount(account), secret: data.secret };
Expand All @@ -53,7 +53,7 @@ export class AuthService {
}

if (!account) {
throw new UnauthorizedException('User does not exist');
throw new UnauthorizedException('User does not exists');
}
if (!(await account.checkPassword(data.password))) {
throw new UnauthorizedException('Wrong password');
Expand Down Expand Up @@ -97,18 +97,6 @@ export class AuthService {
return {error: e.message};
}
}
async changeClan(account: Account, newClan: string) {
try {
let result = await this.accountsService.changeClan(account.id, newClan);
if(result.success) {
(result as any).secret = account.secret;
}
return result;
} catch (e) {
console.log(e);
return {error: e.message};
}
}

async updateAccount(account: Account) {
return this.accountsService.update(account.id, account);
Expand Down
4 changes: 1 addition & 3 deletions api/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ interface ConfigProps {

usernameWaitTime: number;
usernameLength: [number, number];
clanLength: [number, number];
}

export const config: ConfigProps = {
Expand All @@ -22,6 +21,5 @@ export const config: ConfigProps = {
serverSecret: process.env.SERVER_SECRET || 'server-secret',

usernameWaitTime: 7 * 24 * 60 * 60 * 1000, // 7 days
usernameLength: [1, 16],
clanLength: [1, 4],
usernameLength: [1, 16]
};
22 changes: 0 additions & 22 deletions api/src/helpers/validateClan.ts

This file was deleted.

Binary file not shown.
Binary file not shown.
32 changes: 1 addition & 31 deletions client/src/redux/account/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import api from '../../api';
export type AccountState = {
email: string;
username: string;
clan: string;
isLoggedIn: boolean;
secret: string;
gems: number;
Expand All @@ -17,7 +16,6 @@ export type AccountState = {
const initialState: AccountState = {
email: '',
username: '',
clan: '',
secret: '',
isLoggedIn: false,
gems: 0,
Expand Down Expand Up @@ -87,30 +85,7 @@ export const changeNameAsync = createAsyncThunk(
}
}
);
export const changeClanAsync = createAsyncThunk(
'account/changeClan',
async (newClan: string, { getState, dispatch }) => {
// const state: any = getState();
try {
const response = await api.postAsync(`${api.endpoint}/auth/change-clan?now=${Date.now()}`, {
newClan
});

if (response.error) {
alert(response.error);
} else if (response.success) {
alert('Clan changed successfully');
// Dispatching actions to update name and token in the state
dispatch(setClan(newClan));
dispatch(setSecret(response.secret));
}
} catch (error) {
// Handle any other errors, such as network issues
console.error(error);
alert('An error occurred while changing the clan.');
}
}
);

const accountSlice = createSlice({
name: 'account',
Expand All @@ -119,7 +94,6 @@ const accountSlice = createSlice({
clearAccount: (state) => {
state.email = '';
state.username = '';
state.clan = '';
state.secret = '';
state.gems = 0;
state.ultimacy = 0;
Expand All @@ -132,7 +106,6 @@ const accountSlice = createSlice({
setAccount: (state, action) => {
state.email = action.payload.email;
state.username = action.payload.username;
state.clan = action.payload.clan;
state.isLoggedIn = true;
const previousToken = state.secret;
state.secret = action.payload.secret;
Expand All @@ -155,9 +128,6 @@ const accountSlice = createSlice({
setName: (state, action) => {
state.username = action.payload;
},
setClan: (state, action) => {
state.clan = action.payload;
},
setSecret: (state, action) => {
state.secret = action.payload;
console.log('Token updated');
Expand All @@ -178,5 +148,5 @@ const accountSlice = createSlice({
},
});

export const { setAccount, clearAccount, setName, setSecret, setClan } = accountSlice.actions;
export const { setAccount, clearAccount, setName, setSecret } = accountSlice.actions;
export default accountSlice.reducer;
13 changes: 2 additions & 11 deletions client/src/ui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import LoginModal from './modals/LoginModal';
import SignupModal from './modals/SignupModal';
import ConnectionError from './modals/ConnectionError';

import { clearAccount, setAccount, logoutAsync, changeNameAsync, changeClanAsync } from '../redux/account/slice';
import { clearAccount, setAccount, logoutAsync, changeNameAsync } from '../redux/account/slice';
import { selectAccount } from '../redux/account/selector';
import api from '../api';

Expand Down Expand Up @@ -235,12 +235,8 @@ function App() {
const onChangeName = () => {
const newName = prompt('What do you want to change your name to? Please note that you can only change your name once every 7 days.');
if (!newName) return;

dispatch(changeNameAsync(newName) as any);
}
const onChangeClan = () => {
const newClan = prompt('What do you want to change your clan to? Clans can only contain letters, numbers, and up to 4 characters.');
if (!newClan) return;
dispatch(changeClanAsync(newClan) as any);
}
const openShop = () => {
setModal(<ShopModal account={account} />);
Expand Down Expand Up @@ -384,11 +380,6 @@ function App() {
<FontAwesomeIcon icon={faICursor} /> Change Name
</a>
</li>
<li>
<a className="dropdown-item" href="#" onClick={onChangeClan}>
<FontAwesomeIcon icon={faICursor} /> Change Clan
</a>
</li>
<li><a className="dropdown-item" href="#" onClick={onLogout}>
<FontAwesomeIcon icon={faSignOut} /> Logout
</a></li>
Expand Down
7 changes: 0 additions & 7 deletions client/src/ui/game/Leaderboard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,3 @@
font-size: 22px;
white-space: nowrap;
}

.leaderboard-clan {
color: red;
text-align: right;
position: fixed;
transform: translate(-100%);
}
1 change: 0 additions & 1 deletion client/src/ui/game/Leaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ function LeaderboardLine({ player }: any) {
}
return (
<div className="leaderboard-line">
{player.account?.clan && <span className="leaderboard-clan">[{player.account.clan.toUpperCase()}] &nbsp;</span>}
<span className="leaderboard-place">#{player.place}: </span>
<span className="leaderboard-name" style={player.account ? { color: specialColors[player.name.toLowerCase() as any] ? specialColors[player.name.toLowerCase() as any] : '#3333ff' } : {}}>{player.name}
{player.account?.rank && <span style={{color: getRankColor(player.account.rank)}}> (#{player.account.rank})</span>}
Expand Down

0 comments on commit 1ec34f4

Please sign in to comment.