def address_api(address): if len(address) != 34: abort(404) stats = collect_user_stats(address) stats["acct_items"] = get_joined(stats["acct_items"]) stats["merged_accounts"] = { curr: dict( name=name, acct=get_joined(merged_acct_items), total_merge_paid=total_merge_paid, total_merge_earned=total_merge_earned, merge_unconfirmed_balance=merge_unconfirmed_balance, merge_balance=merge_balance, ) for curr, name, merged_acct_items, total_merge_paid, total_merge_earned, merge_unconfirmed_balance, merge_balance in stats[ "merged_accounts" ] } stats["total_earned"] = float(stats["total_earned"]) if stats["pplns_cached_time"]: stats["pplns_cached_time"] = calendar.timegm(stats["pplns_cached_time"].utctimetuple()) day_shares = stats["last_10_shares"] * 6 * 24 daily_percentage = float(day_shares) / g.shares_to_solve donation_perc = 1 - (stats["donation_perc"] / 100.0) rrwd = current_app.config["reward"] stats["daily_est"] = daily_percentage * rrwd * donation_perc stats["est_round_payout"] = (float(stats["round_shares"]) / g.pplns_size) * donation_perc * rrwd return jsonify(**stats)
def address_api(address): if len(address) != 34: abort(404) stats = collect_user_stats(address) stats['acct_items'] = get_joined(stats['acct_items']) stats['merged_accounts'] = {curr: dict(name=name, acct=get_joined(merged_acct_items), total_merge_paid=total_merge_paid, total_merge_earned=total_merge_earned, merge_unconfirmed_balance=merge_unconfirmed_balance, merge_balance=merge_balance) for curr, name, merged_acct_items, total_merge_paid, total_merge_earned, merge_unconfirmed_balance, merge_balance in stats['merged_accounts']} stats['total_earned'] = float(stats['total_earned']) if stats['pplns_cached_time']: stats['pplns_cached_time'] = calendar.timegm(stats['pplns_cached_time'].utctimetuple()) day_shares = stats['last_10_shares'] * 6 * 24 daily_percentage = float(day_shares) / g.shares_to_solve donation_perc = (1 - (stats['donation_perc'] / 100.0)) rrwd = (cache.get('reward') or 1) / 100000000.0 stats['daily_est'] = daily_percentage * rrwd * donation_perc stats['est_round_payout'] = (float(stats['round_shares']) / g.pplns_size) * donation_perc * rrwd return jsonify(**stats)
def oauth_create(cls, username, primary, password=None, cust_email=None, force_send=None): current_app.logger.debug( dict(username=username, password=password, primary=primary, cust_email=cust_email)) user = cls(username=username) if password is not None: user.password = password db.session.add(user) prim_set = False # a flag for if primary has been found # verify that these actions are kosher oauth_data = oauth_from_session('signup') user_data = oauth_retrieve(oauth_data['provider'], oauth_data['raw_token'], email_only=True) # set their token setattr(user, oauth_data['provider'] + '_token', oauth_data['raw_token']) oauth_profile_populate(oauth_data['provider'], user=user) # grab all their emails from oauth to enter into database for mail in user_data['emails']: email = Email.create(mail['email'], user=user, primary=False, activated=True) if primary == mail['email']: email.primary = True prim_set = True # enter a custom email if they provided one if cust_email is not None: prim = False if primary == cust_email: prim_set = True prim = True email = Email.create(cust_email, primary=prim, user=user) if primary == cust_email: email.primary = True prim_set = True # send the activation email to the user if not email.send_activation(force_send=force_send): return False if prim_set is False: raise LeverSyntaxError( "Primary email was not any one of provided emails") db.session.flush() login_user(user) return {'objects': [get_joined(user)]}
def angular_root(path=None): logged_in = "true" if current_user.is_authenticated() else "false" user = get_joined(current_user.get()) if current_user.is_authenticated() else "undefined" # re-encode our flash messages and pass them to angular for display messages = session.pop('_messages', None) if messages is None: messages = [] return render_template('base.html', logged_in=logged_in, user=user, messages=messages)
def address_api(address): if len(address) != 34: abort(404) stats = collect_user_stats(address) stats['acct_items'] = get_joined(stats['acct_items']) stats['total_earned'] = float(stats['total_earned']) if stats['pplns_cached_time']: stats['pplns_cached_time'] = calendar.timegm(stats['pplns_cached_time'].utctimetuple()) day_shares = stats['last_10_shares'] * 6 * 24 daily_percentage = float(day_shares) / g.shares_to_solve donation_perc = (1 - (stats['donation_perc'] / 100.0)) rrwd = current_app.config['reward'] stats['daily_est'] = daily_percentage * rrwd * donation_perc stats['est_round_payout'] = (float(stats['round_shares']) / g.total_round_shares) * donation_perc * rrwd return jsonify(**stats)
def login(cls, identifier=None, password=None): # by having kwargs we can run this function from angular with no params # and prevent a 400 error... kinda hacky if identifier is None or password is None: return {'message': 'Invalid credentials', 'success': False} if '@' in identifier: user = User.query.filter( User.emails.any(Email.address == identifier)).first() else: user = User.query.filter_by(username=identifier.lower()).first() if user and user.check_password(password): login_user(user) return {'objects': [get_joined(user)]} return False
def recover(self, hash, password): day_ago = datetime.utcnow() - timedelta(days=1) if hash.strip() != self.recover_hash: current_app.logger.debug("Wrong recover hash: {} vs {}" .format(hash, self.recover_hash)) return {'success': False, 'message': ('Invalid recovery hash, maybe you copy and pasted the ' 'link wrong?')} elif self.recover_gen < day_ago: return {'success': False, 'message': ('Recovery hash has expired (it\'s too old). Please ' 'resend a fresh one from the Account recovery page.')} self.password = password self.recover_gen = None self.recover_hash = None login_user(self) return {'objects': [get_joined(self)]}
def add_maintainer(self, username): # grab user object from username user = User.query.filter_by(username=username.lower()).one() ProjectMaintainer.create(user, self) return {'objects': [get_joined(user)]}