def post(self): log(log.INFO, "POST new account start") args = self.post_args.parse_args() log(log.DEBUG, "POST acc arguments %s", args) status = check_token(args) if status["status"] == "success": log(log.DEBUG, "Token valid") account = Account.query.filter_by( ad_login=args["ad_login"]).first() if not account: log(log.INFO, "New AD login is unique") try: # # create LDAP user ad_login = args["ad_login"] ad_password = args["ad_password"] ldap_user = ldap.add_user(ad_login) if not ldap_user: raise Exception("LDAP user not created!") ldap_user.reset_password(ad_password) # if not ldap_user.reset_password(ad_password): # raise Exception("LDAP user password don't created!") mdm.sync() new_account = Account() new_account.ad_login = ad_login new_account.ad_password = ad_password new_account.email = args["email"] new_account.created_by_id = args["created_by_id"] new_account.reseller_id = args["reseller_id"] new_account.sim = args["sim"] new_account.imei = args["imei"] new_account.comment = args["comment"] new_account.license_key = args["license_key"] new_account.acc_status = args["acc_status"] new_account.save() resp = { "status": "success", "message": "Account was created", "data": new_account.to_json(), } return resp except Exception as e: log(log.ERROR, "Internal error: %s", str(e)) return { "status": "error", "message": "Internal server error" } else: log(log.ERROR, "Account already exist") return {"status": "error", "message": "Account already exist"} else: log(log.ERROR, "Token error: %s", status.message) return status