Exemplo n.º 1
0
def signup(vars=None):
    """
    User signup to the ESP Rainmaker.

    :param vars: `email` as key - Email address of the user, defaults to `None`
    :type vars: dict

    :raises Exception: If there is any issue in signup for user

    :return: None on Success
    :rtype: None
    """
    log.info('Signing up the user ' + vars['email'])
    u = user.User(vars['email'])
    password = get_password()
    try:
        status = u.signup_request(password)
    except Exception as signup_err:
        log.error(signup_err)
    else:
        if status is True:
            verification_code = input('Enter verification code sent on your'
                                      'Email.\n Verification Code : ')
            try:
                status = u.signup(verification_code)
            except Exception as signup_err:
                log.error(signup_err)
                return
            print('Signup Successful\n'
                  'Please login to continue with ESP Rainmaker CLI')
        else:
            log.error('Signup failed. Please try again.')
    return
Exemplo n.º 2
0
def login(vars=None):
    """
    First time login of the user.

    :param vars: `email` as key - Email address of the user, defaults to `None`
    :type vars: dict

    :raises Exception: If there is any issue in login for user

    :return: None on Success and Failure
    :rtype: None
    """
    log.info('Signing in the user. Username  ' + str(vars['email']))
    config = configmanager.Config()
    
    # Set email-id
    email_id = vars['email']
    log.info('Logging in user: {}'.format(email_id))
    
    # Check user current creds exist
    resp_filename = config.check_user_creds_exists()
    
    # If current creds exist, ask user for ending current session
    if resp_filename:      
        
        # Get email-id of current logged-in user
        curr_email_id = config.get_token_attribute('email')
        log.info('Logging out user: {}'.format(curr_email_id))
        
        # Get user input
        input_resp = config.get_input_to_end_session(curr_email_id)
        if not input_resp:
            return
        
        # Remove current login creds
        ret_val = config.remove_curr_login_creds(curr_creds_file=resp_filename)
        if ret_val is None:
            print("Failed to end previous login session. Exiting.")
            return
    else:
        log.debug("Current login creds not found at path: {}".format(resp_filename))

    if vars['email'] is None:
        browser_login()
        return
    try:
        u = user.User(vars['email'])
        u.login()
        print('Login Successful')
    except Exception as login_err:
        log.error(login_err)
Exemplo n.º 3
0
def login(vars=None):
    """
    First time login of the user.

    :param vars: `email` as key - Email address of the user, defaults to `None`
    :type vars: dict

    :raises Exception: If there is any issue in login for user

    :return: None on Success
    :rtype: None
    """
    log.info('Signing in the user. Username  ' + str(vars['email']))
    if vars['email'] is None:
        browser_login()
        return
    u = user.User(vars['email'])
    try:
        u.login()
    except Exception as login_err:
        log.error(login_err)
    else:
        print('Login Successful')
Exemplo n.º 4
0
def forgot_password(vars=None):
    """
    Forgot password request to reset the password.

    :param vars: `email` as key - Email address of the user, defaults to `None`
    :type vars: dict

    :raises Exception: If there is an HTTP issue while
                       changing password for user

    :return: None on Success and Failure
    :rtype: None
    """
    log.info('Changing user password. Username ' + vars['email'])
    u = user.User(vars['email'])
    status = False
    try:
        status = u.forgot_password()
    except Exception as forgot_pwd_err:
        log.error(forgot_pwd_err)
    else:
        verification_code = input('Enter verification code sent on your Email.'
                                  '\n Verification Code : ')
        password = get_password()
        if status is True:
            try:
                log.debug('Received verification code on email ' +
                          vars['email'])
                status = u.forgot_password(password, verification_code)
            except Exception as forgot_pwd_err:
                log.error(forgot_pwd_err)
            else:
                print('Password changed successfully.'
                      'Please login with the new password.')
        else:
            log.error('Failed to reset password. Please try again.')
    return
Exemplo n.º 5
0
def forgot_password(vars=None):
    """
    Forgot password request to reset the password.

    :param vars: `email` as key - Email address of the user, defaults to `None`
    :type vars: dict

    :raises Exception: If there is an HTTP issue while
                       changing password for user

    :return: None on Success and Failure
    :rtype: None
    """
    log.info('Changing user password. Username ' + vars['email'])
    config = configmanager.Config()
    
    # Get email-id if present
    try:
        email_id = config.get_token_attribute('email')
    except Exception:
        email_id = None
    
    # If current logged-in user is same as
    # the email-id given as user input
    # end current session
    # (invalidate current logged-in user token)
    log.debug("Current user email-id: {}, user input email-id: {}".format(email_id, vars['email']))
    if email_id and email_id == vars['email']:
        log.debug("Ending current session for user: {}".format(email_id))
        
        # Check user current creds exist
        resp_filename = config.check_user_creds_exists()
        if not resp_filename:
            log.debug("Current login creds not found at path: {}".format(resp_filename))
            log.error("User not logged in")
            return

        # If current creds exist, ask user for ending current session   
        # Get user input
        input_resp = config.get_input_to_end_session(email_id)
        if not input_resp:
            return
        
        # Remove current login creds
        ret_val = config.remove_curr_login_creds(curr_creds_file=resp_filename)
        if ret_val is None:
            print("Failed to end previous login session. Exiting.")
            return
    
    u = user.User(vars['email'])
    status = False
    
    try:
        status = u.forgot_password()
    except Exception as forgot_pwd_err:
        log.error(forgot_pwd_err)
    else:
        verification_code = input('Enter verification code sent on your Email.'
                                  '\n Verification Code : ')
        password = get_password()
        if status is True:
            try:
                log.debug('Received verification code on email ' +
                          vars['email'])
                status = u.forgot_password(password, verification_code)
            except Exception as forgot_pwd_err:
                log.error(forgot_pwd_err)
            else:
                print('Password changed successfully.'
                      'Please login with the new password.')
        else:
            log.error('Failed to reset password. Please try again.')
    return