def register(self, args): # pylint: disable=no-self-use """ User registration function. It will ask for an email address, name, surname and a password. :param args: parser arguments when called by the master command (pdm) :return: None """ if not args.name: args.name = raw_input("Please enter your given name: ") if not args.surname: args.surname = raw_input("Please enter your surname: ") password = getpass() conf_pass = getpass(prompt='Confirm password: '******'t match. Aborted" return client = HRClient() userdict = { 'surname': args.surname, 'name': args.name, 'email': args.email, 'password': password } client.add_user(userdict) print "User registered %s %s %s " % (args.name, args.surname, args.email) print "Verification email sent to %s. Please check your mailbox." % args.email
def whoami(self, args): # pylint: disable=no-self-use """ get users own data. """ token = UserCommand._get_token(args.token) if token: client = HRClient() client.set_token(token) ret = client.get_user() UserCommand._print_formatted_user_info(ret)
def resend_email(self, args): """ Resend verification email. :param args: parser arguments (email address) :return: None """ print "Sending a verification email to %s " % args.email client = HRClient() userdict = {'email': args.email} client.resend_email(userdict) print "Email sent. Please check your mailbox."
def startup_web(config): """Configure the web service.""" current_app.log.info("Web interface starting") current_app.hrclient = HRClient() current_app.hrutils = HRUtils() current_app.siteclient = SiteClient() current_app.site_map = {}
def passwd(self, args): # pylint: disable=no-self-use """ Change user password. """ token = UserCommand._get_token(args.token) if token: password = getpass(prompt='Old Password: '******'New Password: '******'Confirm New Password: '******'t match. Aborted" return client = HRClient() client.set_token(token) ret = client.change_password(password, newpassword) print ret
def login(self, args): # pylint: disable=no-self-use """ User login function. Stores a token obtained from the server in a file. """ token = UserCommand._get_token(args.token, check_validity=False) # expired or not password = None if token and not args.email: # username from token try: username = HRUtils.get_token_username_insecure(token) # a valid token should normally have a username, but to be safe: if username: password = getpass(prompt=str(username) + "'s password: "******"Please enter your email address: ") if not args.email: print "No email provided. Exiting .." exit(1) username = args.email password = getpass() client = HRClient() token = client.login(username, password) filename = os.path.expanduser(args.token) try: os.makedirs(os.path.dirname(filename)) except OSError as exc: if exc.errno != errno.EEXIST: print os.strerror(exc.errno) raise with open(filename, "w") as token_file: os.chmod(filename, 0o600) token_file.write(token) print "User {} logged in".format(username)
def verify(self, args): """ Verify user's email address. :param args: parser arguments :return: None """ print "Verifying email address.\nCut and paste the token received by email." token = raw_input("Token:") token = os.path.basename(token) client = HRClient() tokendict = {'mailtoken': token} try: client.verify_user(tokendict) print "User email %s verified" % HRUtils.get_token_username_insecure( token) except RESTException as re: if re.code == 400: print "Token expired or already verified." else: print re
def unregister(self, args): """ Deletes a user from the pdm user database. A user can only delete himself. Result of the operation is printed to the console. :param args: parser arguments. :return: None """ token = UserCommand._get_token(args.token) if token: client = HRClient() client.set_token(token) client.del_user() os.remove(os.path.expanduser(args.token)) print "User unregistered. Token deleted." else: print "Unregister operation failed."