Skip to content
Permalink
Browse files

fix(signup): #167

  • Loading branch information...
polonel committed Mar 15, 2019
1 parent bacc5e3 commit 5828301006431c6f5d9bb8429b0f91d1f3750904
@@ -17,8 +17,11 @@ import PropTypes from 'prop-types'
import { connect } from 'react-redux'

import { showModal, fetchRoles, updateRoleOrder } from 'actions/common'
import { updateSetting } from 'actions/settings'

import Button from 'components/Button'
import SettingItem from 'components/Settings/SettingItem'
import SingleSelect from 'components/SingleSelect'
import SplitSettingsPanel from 'components/Settings/SplitSettingsPanel'
import PermissionBody from './permissionBody'

@@ -29,6 +32,12 @@ class PermissionsSettingsContainer extends React.Component {
this.props.fetchRoles()
}

getSetting (name) {
return this.props.settings.getIn(['settings', name, 'value'])
? this.props.settings.getIn(['settings', name, 'value'])
: ''
}

onRoleOrderChanged (e) {
const children = $(e.target).children('li')
let arr = []
@@ -57,9 +66,34 @@ class PermissionsSettingsContainer extends React.Component {
this.props.showModal('CREATE_ROLE')
}

onDefaultUserRoleChange (e) {
this.props.updateSetting({ name: 'role:user:default', value: e.target.value, stateName: 'defaultUserRole' })
}

render () {
const mappedRoles = this.props.roles
.map(role => {
return { text: role.get('name'), value: role.get('_id') }
})
.toArray()

return (
<div className={this.props.active ? '' : 'hide'}>
<SettingItem
title={'Default New User Role'}
subtitle={'Role assigned to users created during sign-up and public tickets'}
component={
<SingleSelect
items={mappedRoles}
defaultValue={this.getSetting('defaultUserRole')}
onSelectChange={e => {
this.onDefaultUserRoleChange(e)
}}
width={'50%'}
showTextbox={false}
/>
}
/>
<SplitSettingsPanel
title={'Permissions'}
tooltip={'Permission order is top down. ex: Admins at top; Users at bottom.'}
@@ -95,17 +129,20 @@ PermissionsSettingsContainer.propTypes = {
active: PropTypes.bool.isRequired,
roles: PropTypes.object.isRequired,
roleOrder: PropTypes.object.isRequired,
settings: PropTypes.object.isRequired,
fetchRoles: PropTypes.func.isRequired,
updateRoleOrder: PropTypes.func.isRequired,
showModal: PropTypes.func.isRequired
showModal: PropTypes.func.isRequired,
updateSetting: PropTypes.func.isRequired
}

const mapStateToProps = state => ({
roles: state.shared.roles,
roleOrder: state.shared.roleOrder
roleOrder: state.shared.roleOrder,
settings: state.settings.settings
})

export default connect(
mapStateToProps,
{ fetchRoles, updateRoleOrder, showModal }
{ fetchRoles, updateRoleOrder, showModal, updateSetting }
)(PermissionsSettingsContainer)
@@ -433,6 +433,18 @@ apiTickets.createPublicTicket = function (req, res) {
async.waterfall(
[
function (next) {
var settingSchmea = require('../../../models/setting')
settingSchmea.getSetting('role:user:default', function (err, roleDefault) {
if (err) return next(err)
if (!roleDefault) {
winston.error('No Default User Role Set. (Settings > Permissions > Default User Role)')
return next('No Default Role Set')
}

return next(null, roleDefault)
})
},
function (roleDefault, next) {
var UserSchema = require('../../../models/user')
plainTextPass = chance.string({
length: 6,
@@ -444,7 +456,8 @@ apiTickets.createPublicTicket = function (req, res) {
password: plainTextPass,
fullname: postData.user.fullname,
email: postData.user.email,
role: 'user'
accesstoken: chance.hash(),
role: roleDefault.value
})

user.save(function (err, savedUser) {
@@ -174,11 +174,15 @@ apiUsers.create = function (req, res) {
if (postData.aPass !== postData.aPassConfirm)
return res.status(400).json({ success: false, error: 'Invalid Password Match' })

var Chance = require('chance')
var chance = new Chance()

var account = new UserSchema({
username: postData.aUsername,
password: postData.aPass,
fullname: postData.aFullname,
email: postData.aEmail,
accesstoken: chance.hash(),
role: postData.aRole
})

@@ -268,13 +272,25 @@ apiUsers.createPublicAccount = function (req, res) {
async.waterfall(
[
function (next) {
var SettingSchema = require('../../../models/setting')
SettingSchema.getSetting('role:user:default', function (err, roleDefault) {
if (err) return next(err)
if (!roleDefault) {
winston.error('No Default User Role Set. (Settings > Permissions > Default User Role)')
return next({ message: 'No Default Role Set. Please contact administrator.' })
}

return next(null, roleDefault)
})
},
function (roleDefault, next) {
var UserSchema = require('../../../models/user')
user = new UserSchema({
username: postData.user.email,
password: postData.user.password,
fullname: postData.user.fullname,
email: postData.user.email,
role: 'user'
role: roleDefault.value
})

user.save(function (err, savedUser) {
@@ -97,7 +97,21 @@ function rolesDefault (callback) {
description: 'Default role for users',
grants: settingsDefaults.userGrants
},
done
function (err, userRole) {
if (err) return done(err)
SettingsSchema.getSetting('role:user:default', function (err, roleUserDefault) {
if (err) return done(err)
if (roleUserDefault) return done()

SettingsSchema.create(
{
name: 'role:user:default',
value: userRole._id
},
done
)
})
}
)
})
},
@@ -393,9 +407,7 @@ function normalizeTags (callback) {
function checkPriorities (callback) {
var ticketSchema = require('../models/ticket')
var migrateP1 = false

var migrateP2 = false

var migrateP3 = false

async.parallel(
@@ -77,6 +77,8 @@ util.getSettings = function (callback) {
s.minSubjectLength = parseSetting(settings, 'ticket:minlength:subject', 10)
s.minIssueLength = parseSetting(settings, 'ticket:minlength:issue', 10)

s.defaultUserRole = parseSetting(settings, 'role:user:default', '')

s.mailerEnabled = parseSetting(settings, 'mailer:enable', false)
s.mailerHost = parseSetting(settings, 'mailer:host', '')
s.mailerSSL = parseSetting(settings, 'mailer:ssl', false)
@@ -370,6 +370,17 @@
</a>
</div>
</div>
<div id="accountCreateError" class="hide">
<h2 style="margin-bottom: 25px; text-align: left;">An Error has occurred</h2>
<p style="text-align: justify;">
An Unknown Error has occurred
</p>
<div style="width: 100%; margin-top: 50px;">
<a href="/signup" class="no-ajaxy" style="width: 100%; padding: 0; margin: 0;">
<button class="btn md-btn md-btn-wave md-btn-danger" type="button" style="width: 100%; margin-bottom: 10px !important;">Start Over</button>
</a>
</div>
</div>
</div>
</div>

@@ -522,7 +533,7 @@
error: function(e) {
$checkEmailBtn.prop('disabled', false).text('Next');
window.Snackbar.show({
text: 'An Error occurred.',
text: 'Invalid Captcha',
actionTextColor: 'red'
});
@@ -647,19 +658,26 @@
url: '/api/v1/public/account/create',
data: JSON.stringify(data),
contentType: 'application/json',
error: function(response) {
console.log(response)
$('.activeSlide').removeClass('activeSlide').addClass('hide')
var $errorSlide = $('#accountCreateError')
$errorSlide.removeClass('hide')
$errorSlide.find('p').html(response.responseJSON.error)
},
success: function(response) {
if (!response.success) {
//TODO: Show Error Slide
var $errorSlide = $('#accountCreateError')
$errorSlide.removeClass('hide')
$errorSlide.find('p').html('Error: ' + response.error)
} else {
$('span#spanfullname').text(userInfo.fullname);
$('span#spanemail').text(userInfo.email);
showAccountCreated();
}
},
error: function(err) {
console.error(err);
}
})
}

0 comments on commit 5828301

Please sign in to comment.
You can’t perform that action at this time.