Beispiel #1
0
    def new(self, username, password, email, first_name, state=None, language='en', last_name=None, display_name=None, interests=None, expertise=None, address=None, city=None, country=None, pincode=None, phone=None, mobile=None, fax=None, skype=None, sip=None, website=None, short_description=None, long_description=None, twitter=None, facebook=None, blog=None, linkedin=None, use_gravtar=None):

        if not display_name: display_name = first_name + ' ' + (last_name or '')
        created = datetime.datetime.now()
        if state is None: state = commonlib.shared.states.member.enabled

        data = dict(username=username, password=helpers.encrypt(password), state=state)
        user_id = user_store.add(**data)
        member_ref = member_store.ref(user_id)

        """data = dict(owner=member_ref, email=email, address=address, city=city, country=country, pincode=pincode, phone=phone, mobile=mobile, fax=fax, skype=skype, sip=sip)
        contact_id = contact_store.add(**data)

        data = dict(member=user_id, first_name=first_name, last_name=last_name, display_name=display_name, short_description=short_description, long_description=long_description, website=website, twitter=twitter, facebook=facebook, blog=blog, linkedin=linkedin, use_gravtar=use_gravtar)
        profile_store.add(**data)"""

        data = dict(member=user_id, language=language)
        memberpref_store.add(**data)

        owner = member_store.ref(user_id)
        data = dict(member=user_id, first_name=first_name, last_name=last_name, display_name=display_name, short_description=short_description, long_description=long_description, interests=interests, expertise=expertise, website=website, twitter=twitter, facebook=facebook, blog=blog, linkedin=linkedin, use_gravtar=use_gravtar, id=user_id, owner=owner, email=email, address=address, city=city, country=country, pincode=pincode, phone=phone, mobile=mobile, fax=fax, skype=skype, sip=sip, created=created, state=state)
        member_store.add(**data)

        search_d = dict(id=user_id, display_name=display_name, short_description=short_description, long_description=long_description, username=username)
        #searchlib.add(search_d)
        return user_id
Beispiel #2
0
import be.repository.access as dbaccess
import commonlib.helpers as helpers


def authenticate(username, password):
    """
    Returns T if authentication is successful. Else False.
    """
    try:
        passphrase = dbaccess.get_passphrase_by_username(username)
    except IndexError, err:
        return False
    encrypted = helpers.encrypt(password)
    return encrypted == passphrase


def create_session(user_id):
    token = commonlib.helpers.random_key_gen()
    session_store.add(token, user_id)
    return token


def get_or_create_session(username):
    user = userstore.get_one_by(username=username)
    try:
        session = session_store.get_one_by(user_id=user.id)
        token = session.token
    except IndexError:
        token = create_session(user.id)
    return token