Skip to content

Commit

Permalink
Add way to reset alias to steam alias on the edit profile page
Browse files Browse the repository at this point in the history
Added a 'RESET TO STEAM ALIAS' button on the alias input (visible all the time).
A reset unlocks the user's alias to be updated to match steam every login, but once the alias is changed to something custom, the alias is locked.
There may be possible conflictions in the future with this functionality and the functionality around 'verified users'.
  • Loading branch information
Corey28 authored and Gocnak committed Jun 22, 2019
1 parent 5f87e85 commit 6f21f05
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 41 deletions.
7 changes: 7 additions & 0 deletions client/src/app/@core/data/local-user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,11 @@ export class LocalUserService {
responseType: 'text',
});
}

public resetAliasToSteamAlias(): Observable<any> {
return this.http.patch('/api/user', {
alias: '',
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,42 @@ <h2 class="col title">EDIT PROFILE</h2>
<form (ngSubmit)="onSubmit()">
<nb-tabset>
<nb-tab tabTitle="PROFILE" [formGroup]="profileEditFormGroup">
<div class="form-group" [ngClass]="{'has-error':!alias.valid}">
<label>
Alias:
<input class="form-control" formControlName="alias" type="text">
<p class="alert alert-danger" *ngIf="alias.hasError('minlength')">
Username must be at least 3 characters.
</p>
<p class="alert alert-danger" *ngIf="alias.hasError('maxlength')">
Username cannot exceed 32 characters.
</p>
<p class="alert alert-danger" *ngIf="alias.hasError('required') && alias.dirty">
Username is required.
</p>
</label>
</div>

<div class="form-group" [ngClass]="{'has-error':!bio.valid}" formGroupName="profile">
<label>Bio:</label>
<textarea rows="6" class="form-control" formControlName="bio" type="bio" #description></textarea>
<p class="alert alert-danger" *ngIf="bio.hasError('maxlength')">
Text cannot exceed 1000 characters.
</p>
<div class="form-text">
<div class="row">
<span class="col">
<i><a href="https://help.github.com/articles/basic-writing-and-formatting-syntax/">Markdown</a> is supported</i>
</span>
<span class="col text-right">{{1000 - description.value.length | ngxPlural:'character'}} remaining</span>
<div class="row">
<div class="col-sm-12 col-lg-6 col-xl-4">
<div class="form-group" [ngClass]="{'has-error':!alias.valid}">
<label>Alias:</label>
<div class="input-group mb-3">
<input nbInput class="form-control" formControlName="alias" type="text">
<div class="input-group-append">
<button nbButton size="xsmall" class="btn" (click)="resetAlias()">Reset To Steam Alias</button>
</div>
</div>
<p class="alert alert-danger" *ngIf="alias.hasError('minlength')">
Username must be at least 3 characters.
</p>
<p class="alert alert-danger" *ngIf="alias.hasError('maxlength')">
Username cannot exceed 32 characters.
</p>
<p class="alert alert-danger" *ngIf="alias.hasError('required') && alias.dirty">
Username is required.
</p>
</div>
</div>
<div class="col-12">
<div class="form-group" [ngClass]="{'has-error':!bio.valid}" formGroupName="profile">
<label>Bio:</label>
<textarea rows="6" class="form-control" formControlName="bio" type="bio" #description></textarea>
<p class="alert alert-danger" *ngIf="bio.hasError('maxlength')">
Text cannot exceed 1000 characters.
</p>
<div class="form-text">
<div class="row">
<span class="col">
<i><a href="https://help.github.com/articles/basic-writing-and-formatting-syntax/">Markdown</a> is supported</i>
</span>
<span class="col text-right">{{1000 - description.value.length | ngxPlural:'character'}} remaining</span>
</div>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,12 @@ export class ProfileEditComponent implements OnInit {
cancelMerge() {
this.mergeUser = null;
}

resetAlias() {
this.localUserService.resetAliasToSteamAlias().subscribe(response => {
this.localUserService.refreshLocal();
}, err => {
this.toasterService.popAsync('error', 'Failed', 'Failed to reset alias to Steam alias!');
});
}
}
4 changes: 4 additions & 0 deletions server/src/models/db/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ module.exports = (sequelize, type) => {
defaultValue: null,
},
alias: type.STRING(64),
aliasLocked: { // whether or not on to update alias to match latest steam alias on login
type: type.BOOLEAN,
defaultValue: false,
},
avatar: {
type: type.STRING,
get() {}, // hidden (use avatarURL)
Expand Down
55 changes: 43 additions & 12 deletions server/src/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ module.exports = {
usr.country = newProfile.country;
if ((usr.bans & module.exports.Ban.BANNED_AVATAR) === 0)
usr.avatarURL = newProfile.avatarURL;
if ((usr.bans & module.exports.Ban.BANNED_ALIAS) === 0 && !usr.aliasLocked)
usr.alias = newProfile.alias;
return usr.save();
},

Expand Down Expand Up @@ -338,19 +340,35 @@ module.exports = {
},

updateAsLocal: (locUsr, body) => {
const usrUpd8 = { profile: {} };
return sequelize.transaction(t => {

// Only allow updating certain things
const usrUpd8 = {
profile: {},
};

if ((locUsr.bans & module.exports.Ban.BANNED_ALIAS) === 0)
usrUpd8.alias = body.alias;

return User.update(usrUpd8, {where: {id: locUsr.id}, transaction: t}).then(() => {
if (body.profile)
return module.exports.updateProfile(locUsr, body.profile, t);
let userModel;
return User.findByPk(locUsr.id, {
transaction: t,
}).then(user => {
userModel = user;
if ('alias' in body) {
if ((locUsr.bans & module.exports.Ban.BANNED_ALIAS) === 0) {
if (body.alias === '') {
return module.exports.getSteamUsers([user.steamID]);
} else {
usrUpd8.alias = body.alias;
usrUpd8.aliasLocked = true;
}
} else {
delete body.alias;
}
}
return Promise.resolve([]);
}).then(steamUsers => {
if (steamUsers.length > 0) {
usrUpd8.aliasLocked = false;
usrUpd8.alias = steamUsers[0].personaname;
}
return userModel.update(usrUpd8, {transaction: t}).then(() => {
if (body.profile)
return module.exports.updateProfile(locUsr, body.profile, t);
});
});
});
},
Expand Down Expand Up @@ -711,6 +729,19 @@ module.exports = {
});
},

getSteamUsers: (steamIDs) => {
return axios.get('https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/', {
params: {
key: config.steam.webAPIKey,
steamids: steamIDs.join(','),
}
}).then(res => {
if (res.data && res.data.response && res.data.response.players)
return Promise.resolve(res.data.response.players);
return Promise.reject(new ServerError(500, 'Failed to get user(s) from Steam'));
});
},

getSteamFriendIDs: (steamID) => {
return axios.get(`https://api.steampowered.com/ISteamUser/GetFriendList/v1/`, {
params: {
Expand Down
2 changes: 1 addition & 1 deletion server/src/models/validation/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Joi = require('joi');
module.exports = {
id: Joi.number().integer().positive(),
steamID: Joi.string().regex(/^[0-9]{1,20}$/),
alias: Joi.string().min(1).max(64),
alias: Joi.string().min(1).max(64).allow(''),
roles: Joi.number().integer().min(0),
bans: Joi.number().integer().min(0),
};

0 comments on commit 6f21f05

Please sign in to comment.