Skip to content

Instantly share code, notes, and snippets.

@2garryn
Created March 23, 2015 08:46
Show Gist options
  • Save 2garryn/379e78d542c3449e18e6 to your computer and use it in GitHub Desktop.
Save 2garryn/379e78d542c3449e18e6 to your computer and use it in GitHub Desktop.
def user_register(session, username, password, email):
try:
new_user = User(name=username, email=email)
session.add(new_user)
session.commit()
return True, 'ok'
except exc.IntegrityError as e:
session.rollback()
code, msg = e.orig
print msg
if code == 1062: return False, "User with provided email or username already existed"
else: return False, "Internal error"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment