def register_user_with_json_data(data, lang, mailer: Mailer): """ Consume the ajax data for an login attempt :param data: validated params of webserver's request :param lang: language :param mailer: Mailer :return: Boolean, String, User """ _tn = Translator(lang) success = '' firstname = escape_string(data.get('firstname', '')) lastname = escape_string(data.get('lastname', '')) nickname = escape_string(data.get('nickname', '')) email = escape_string(data.get('email', '')) gender = escape_string(data.get('gender', "")) password = escape_string(data.get('password', '')) passwordconfirm = escape_string(data.get('passwordconfirm', '')) db_new_user = None msg = __check_login_params(firstname, lastname, nickname, email, password, passwordconfirm) if msg: return success, _tn.get(msg), db_new_user # getting the authors group db_group = DBDiscussionSession.query(Group).filter_by(name="users").first() # does the group exists? if not db_group: msg = _tn.get(_.errorTryLateOrContant) LOG.debug("Error occured") return success, msg, db_new_user user_data = { 'firstname': firstname, 'lastname': lastname, 'nickname': nickname, 'gender': gender, 'email': email } ret_dict = user.set_new_user(mailer, user_data, password, _tn) success = ret_dict['success'] error = ret_dict['error'] db_new_user = ret_dict['user'] msg = error if success: msg = _tn.get(_.accountWasAdded).format(nickname) return success, msg, db_new_user
def __register_user_with_ldap_data(mailer, nickname, password, _tn) -> dict: """ Asks LDAP if the user is known :param mailer: instance of pyramids mailer :param nickname: User.nickname :param password: String :param _tn: Translator :return: dict() or HTTPFound if the user is logged in an it is not the api """ LOG.debug("user: %s", nickname) ldap_data = verify_ldap_user_data(nickname, password, _tn) if ldap_data['error']: return {'error': ldap_data['error']} # register the new user ldap_data['nickname'] = nickname ret_dict = user.set_new_user(mailer, ldap_data, PW_FOR_LDAP_USER, _tn) if 'success' not in ret_dict: return {'error': _tn.get(_.internalKeyError)} return {'user': ret_dict['user']}
def __register_user_with_ldap_data(mailer, nickname, password, _tn) -> dict: """ Asks LDAP if the user is known :param mailer: instance of pyramids mailer :param nickname: User.nickname :param password: String :param _tn: Translator :return: dict() or HTTPFound if the user is logged in an it is not the api """ logger('Auth.Login', 'user: {}'.format(nickname)) ldap_data = verify_ldap_user_data(nickname, password, _tn) if ldap_data['error']: return {'error': ldap_data['error']} # register the new user ret_dict = user.set_new_user(mailer, ldap_data['firstname'], ldap_data['lastname'], nickname, ldap_data['gender'], ldap_data['email'], 'NO_PW_BECAUSE_LDAP', _tn) if 'success' not in ret_dict: return {'error': _tn.get(_.internalKeyError)} return {'user': ret_dict['user']}