Skip to content

Commit

Permalink
Migrate over getUser template.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMax committed Jul 9, 2014
1 parent 9d43266 commit 438b356
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 25 deletions.
4 changes: 4 additions & 0 deletions source/dbconn.js
Expand Up @@ -20,6 +20,7 @@
"use strict";

var Promise = require('bluebird');
var _ = require('lodash');

var crypto = require('crypto');
var Sequelize = require('sequelize');
Expand Down Expand Up @@ -91,6 +92,9 @@ var DBConn = function(config) {
visible_auth: Sequelize.BOOLEAN
}, {
instanceMethods: {
isOperator: function() {
return _.contains(['OWNER', 'MASTER', 'OP'], this.access);
},
getGravatar: function() {
var md5 = crypto.createHash('md5');
return md5.update(this.email.toLowerCase(), 'ascii').digest('hex');
Expand Down
18 changes: 4 additions & 14 deletions source/webapp.js
Expand Up @@ -375,21 +375,9 @@ WebApp.prototype.getUser = function(req, res) {
// User is allowed to see the profile, so obtain the profile.
return Promise.all([user, user.getProfile()]);
}).spread(function(user, profile) {
var can_edit = false;
if (!("user" in req.session)) {
// Anonymous users can never edit a profile
} else if (_.contains(['OWNER', 'MASTER', 'OP'], req.session.user.access)) {
// Operators can always edit profiles
can_edit = true;
} else if (user.id === req.session.user.id) {
// Users can always edit their own profiles
can_edit = true;
}

self.render(req, res, 'getUser', {
res.render('getUser.swig', {
user: user,
profile: profile,
can_edit: can_edit
profile: profile
});
}).done();
};
Expand Down Expand Up @@ -449,6 +437,8 @@ WebApp.prototype.getEditUser = function(req, res) {
WebApp.prototype.postEditUser = function(req, res) {
var self = this;

console.log(req.body);

if (_.contains(['OWNER', 'MASTER', 'OP'], req.session.user.access)) {
// Admin form submussion
webform.userForm(self.dbconn, req.body)
Expand Down
8 changes: 4 additions & 4 deletions source/webform.js
Expand Up @@ -164,19 +164,19 @@ function userForm(dbconn, data) {
}

if (!validator.isLength(data.profile.clantag, 0, 6)) {
profile_errors.clan = "Clan tag must be 6 characters or less";
profile_errors.clantag = "Clan tag must be 6 characters or less";
}

if (!validator.isLength(data.profile.contactinfo, 0, 1000)) {
profile_errors.clan = "Clan tag must be 1,000 characters or less";
profile_errors.contactinfo = "Contact Information must be 1,000 characters or less";
}

if (!validator.isLength(data.profile.location, 0, 100)) {
profile_errors.clan = "Clan must be 100 characters or less";
profile_errors.location = "Location must be 100 characters or less";
}

if (!validator.isLength(data.profile.message, 0, 1000)) {
profile_errors.clan = "Clan tag must be 1,000 characters or less";
profile_errors.message = "Message must be 1,000 characters or less";
}

/* clan: Sequelize.STRING,
Expand Down
12 changes: 6 additions & 6 deletions views/getUser.hjs
@@ -1,16 +1,16 @@
<h2>{{profile.clantag}}{{profile.username}}</h2>
<h2>{{ profile.clantag }}{{ profile.username }}</h2>
<img src="//www.gravatar.com/avatar/{{user.getGravatar}}">
<dl>
<dt>Clan</dt>
<dd>{{profile.clan}}</dd>
<dd>{{ profile.clan }}</dd>
<dt>Country</dt>
<dd>{{profile.country}}</dd>
<dd>{{ profile.country }}</dd>
<dt>Location</dt>
<dd>{{profile.location}}</dd>
<dd>{{ profile.location }}</dd>
<dt>Contact Info</dt>
<dd>{{profile.contactinfo}}</dd>
<dd>{{ profile.contactinfo }}</dd>
<dt>Message</dt>
<dd>{{profile.message}}</dd>
<dd>{{ profile.message }}</dd>
</dl>
{{#can_edit}}
<a class="btn btn-primary" href="/users/{{user.username}}/edit">Edit Profile</a>
Expand Down
31 changes: 31 additions & 0 deletions views/getUser.swig
@@ -0,0 +1,31 @@
{% extends 'layout.swig' %}

{% block body %}
<h2>{{ profile.clantag }}{{ profile.username }}</h2>
<img src="//www.gravatar.com/avatar/{{ user.getGravatar() }}">
<dl>
{% if profile.clan %}
<dt>Clan</dt>
<dd>{{ profile.clan }}</dd>
{% endif %}
{% if profile.country %}
<dt>Country</dt>
<dd>{{ profile.country }}</dd>
{% endif %}
{% if profile.location %}
<dt>Location</dt>
<dd>{{ profile.location }}</dd>
{% endif %}
{% if profile.contactinfo %}
<dt>Contact Info</dt>
<dd>{{ profile.contactinfo }}</dd>
{% endif %}
{% if profile.message %}
<dt>Message</dt>
<dd>{{ profile.message }}</dd>
{% endif %}
</dl>
{% if user.isOperator() or user.id === session.user.id %}
<a class="btn btn-primary" href="/users/{{ user.username }}/edit">Edit Profile</a>
{% endif %}
{% endblock %}
4 changes: 3 additions & 1 deletion views/layout.swig
Expand Up @@ -8,6 +8,8 @@
</head>
<body>
{% include 'header.swig' %}
{% block body %}{% endblock %}
<div class="container">
{% block body %}{% endblock %}
</div>
</body>
</html>

0 comments on commit 438b356

Please sign in to comment.