@@ -15,6 +15,7 @@ var async = require('async');
15
15
var _ = require ( 'underscore' ) ;
16
16
var util = require ( 'util' ) ;
17
17
var rfc2047 = require ( 'rfc2047' ) ;
18
+ var expressCaptcha = require ( 'express-svg-captcha' ) ;
18
19
19
20
var SPDX = require ( 'spdx-license-ids' ) ;
20
21
@@ -941,6 +942,25 @@ exports.userSyncListPage = function (aReq, aRes, aNext) {
941
942
} ) ;
942
943
} ;
943
944
945
+ var captcha = new expressCaptcha ( {
946
+ isMath : true , // if true will be a simple math equation
947
+ useFont : null , // Can be path to ttf/otf font file
948
+ size : 4 , // number of characters for string capthca
949
+ ignoreChars : '0o1i' , // characters to not include in string capthca
950
+ noise : 3 , // number of noise lines
951
+ color : true , // if true noise lines and captcha characters will be randomly colored
952
+ // (is set to true if background is set)
953
+ background : null , // HEX or RGB(a) value for background set to null for transparent
954
+ width : 200 , // width of captcha
955
+ height : 50 , // height of captcha
956
+ fontSize : 56 , // font size for captcha
957
+ charPreset : null // string of characters for use with string captcha set to null for default aA-zZ
958
+ } ) ;
959
+
960
+ exports . userEditProfilePageCaptcha = function ( aReq , aRes , aNext ) {
961
+ ( captcha . generate ( ) ) ( aReq , aRes , aNext ) ;
962
+ }
963
+
944
964
exports . userEditProfilePage = function ( aReq , aRes , aNext ) {
945
965
var authedUser = aReq . session . user ;
946
966
@@ -2059,16 +2079,56 @@ exports.update = function (aReq, aRes, aNext) {
2059
2079
var authedUser = aReq . session . user ;
2060
2080
2061
2081
// Update the about section of a user's profile
2062
- User . findOneAndUpdate ( { _id : authedUser . _id } , { about : aReq . body . about } ,
2063
- function ( aErr , aUser ) {
2082
+ User . findOne ( { _id : authedUser . _id } , function ( aErr , aUser ) {
2083
+ if ( aErr ) {
2084
+ aRes . redirect ( '/' ) ;
2085
+ return ;
2086
+ }
2087
+
2088
+ if ( ! aUser ) {
2089
+ msg = 'No user found.'
2090
+ statusCodePage ( aReq , aRes , aNext , {
2091
+ statusCode : 500 ,
2092
+ statusMessage : msg
2093
+ } ) ;
2094
+ return ;
2095
+ }
2096
+
2097
+ if ( ! captcha . validate ( aReq , aReq . body . captcha ) ) {
2098
+ aRes . redirect ( '/users/' + encodeURIComponent ( aUser . name ) ) ;
2099
+ return ;
2100
+ }
2101
+
2102
+ // Update DB
2103
+ aUser . about = aReq . body . about ;
2104
+ aUser . save ( function ( aErr , aUser ) {
2105
+ var msg = null ;
2106
+
2064
2107
if ( aErr ) {
2065
- aRes . redirect ( '/' ) ;
2108
+ msg = 'Unknown error when saving Profile.' ;
2109
+ statusCodePage ( aReq , aRes , aNext , {
2110
+ statusCode : 500 ,
2111
+ statusMessage : [ msg , 'Please contact Development' ] . join ( ' ' )
2112
+ } ) ;
2113
+ console . error ( aErr ) ;
2114
+ return ;
2115
+ }
2116
+ if ( ! aUser ) {
2117
+ msg = 'No user handle when saving Profile.' ;
2118
+ statusCodePage ( aReq , aRes , aNext , {
2119
+ statusCode : 500 ,
2120
+ statusMessage : [ msg , 'Please contact Development' ] . join ( ' ' )
2121
+ } ) ;
2122
+ console . error ( msg )
2066
2123
return ;
2067
2124
}
2068
2125
2126
+ // Update session
2069
2127
authedUser . about = aUser . about ;
2128
+
2070
2129
aRes . redirect ( '/users/' + encodeURIComponent ( aUser . name ) ) ;
2071
2130
} ) ;
2131
+ } ) ;
2072
2132
} ;
2073
2133
2074
2134
// Submit a script through the web editor
0 commit comments