Skip to content

Commit

Permalink
Merge branch 'master' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
btouellette committed Aug 3, 2020
2 parents f9f52ff + 92b5e42 commit 9b2c4f7
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Brian Ouellette

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
14 changes: 14 additions & 0 deletions app/routes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var User = require('./models/user');
const {parse, stringify} = require('flatted/cjs');

//TODO: confirm e-mail before allowing into game

Expand Down Expand Up @@ -42,25 +43,38 @@ module.exports = function(app, passport, client) {

// process the username form
app.post('/username', isLoggedIn, function(req, res) {
console.log(req.headers['x-request-id'] + ' - selecting new username - ' + stringify(req));
if(!req.user.username) {
var username = req.body.username.toLowerCase();
console.log(req.headers['x-request-id'] + ' - testing valid');
if(/^[a-z0-9_]{1,12}$/.test(username)) {
console.log(req.headers['x-request-id'] + ' - setting username');
User.findByIdAndUpdate(req.user._id, { $set: { username: username }}, function(err) {
console.log(req.headers['x-request-id'] + ' - setting username callback');
if(err) {
console.log(req.headers['x-request-id'] + ' - username callback error - ' + stringify(err));
if(err.lastErrorObject && err.lastErrorObject.code === 11001) {
console.log(req.headers['x-request-id'] + ' - setting username callback error taken');
req.flash('usernameMessage', 'Username already taken');
} else {
console.log(req.headers['x-request-id'] + ' - setting username callback error unknown');
req.flash('usernameMessage', err.errmsg);
}
console.log(req.headers['x-request-id'] + ' - reloading username');
res.redirect('/username');
} else {
console.log(req.headers['x-request-id'] + ' - set user name sending to game');
res.redirect('/game');
}
});
} else {
console.log(req.headers['x-request-id'] + ' - not valid');
req.flash('usernameMessage', username.length > 12 ? 'Username too long' : username.length === 0 ? 'Username too short' : 'Username using invalid characters');
res.redirect('/username');
}
} else {
console.log(req.headers['x-request-id'] + ' - already has username');
res.redirect('/game');
}
});

Expand Down
8 changes: 8 additions & 0 deletions content/css/game.css
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,14 @@ html, body
margin-right: 10px;
}

#username-info
{
margin-left: 10px;
margin-right: 10px;
padding-top: 3px;
margin-bottom: 5px;
}

#username-alert
{
margin-left: 10px;
Expand Down
18 changes: 16 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"ejs": "^2.5.7",
"express": "^4.15.4",
"express-session": "^1.15.5",
"flatted": "^2.0.2",
"helmet": "^3.8.1",
"mongoose": "^5.9.24",
"moniker": "^0.1.2",
Expand All @@ -38,6 +39,19 @@
"eslint": "^3.19.0"
},
"scripts": {
"lint": "eslint app"
}
"lint": "eslint app",
"start": "node server.js"
},
"description": "Multiplayer web game using the same rules as Carcassone. Currently supports the base game and the Inns and Cathedrals expansion.",
"version": "1.0.0",
"repository": {
"type": "git",
"url": "git+https://github.com/btouellette/concarneau.git"
},
"author": "Brian Ouellette",
"license": "MIT",
"bugs": {
"url": "https://github.com/btouellette/concarneau/issues"
},
"homepage": "https://github.com/btouellette/concarneau#readme"
}
3 changes: 2 additions & 1 deletion views/game.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
</div>
<div id="friends-menu">
<span class="menu-header">FRIENDS <svg class="fa-edit hidden" onclick="enableFriendsEdit(event)"><use xlink:href="#fa-edit"></use></svg></span>
<div id="username-info">You: <svg class="fa-user"><use xlink:href="#fa-user"></use></svg><%- user.username %></div>
<form id="add-friend-form">
<div class="input-group">
<input type="text" class="form-control" id="add-friend-input" placeholder="Username" autocomplete="off">
Expand Down Expand Up @@ -199,7 +200,7 @@
</div>
</div>
<script src="/content/js/standalone.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.4.8/d3.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.0/jquery.qtip.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<div class="jumbotron text-center">
<h1>Concarneau</h1>
<p>An <a href="http:https://github.com/btouellette/concarneau">implementation</a> of <a href="https://en.wikipedia.org/wiki/Carcassonne_(board_game)">Carcassonne</a> using <a href="http:https://d3js.org">D3.js</a> and <a href="http:https://nodejs.org">Node.js</a> created by <span id="author-name">Brian Ouellette</span></p>
<p>Unfamiliar with Carcassonne? You can read the rules <a href="http:https://riograndegames.com/uploads/Game/Game_48_gameRules.pdf">here</a></p>
<p>Unfamiliar with Carcassonne? You can read the rules <a href="https:https://images.zmangames.com/filer_public/d5/20/d5208d61-8583-478b-a06d-b49fc9cd7aaa/zm7810_carcassonne_rules.pdf">here</a></p>
<a href="/login" class="btn btn-default"><svg class="fa-user"><use xlink:href="/content/images/ui/icons.svg#fa-user"></use></svg> Local Login</a>
<a href="/signup" class="btn btn-default"><svg class="fa-user"><use xlink:href="/content/images/ui/icons.svg#fa-user"></use></svg> Local Signup</a>
<a href="/auth/facebook" class="btn btn-primary"><svg class="fa-facebook" fill="white"><use xlink:href="/content/images/ui/icons.svg#fa-facebook"></use></svg> Facebook</a>
Expand Down

0 comments on commit 9b2c4f7

Please sign in to comment.