from barter.model import User


def fetch_all_users():
    return User.objects()


def signup_user(email, username, password):
    # check whether or not the email has been used for anther account
    u = User.objects(__raw__={'$or': [{'username': username}, {'email': email}]})
    if len(u) != 0:
        return False, "This email has been used for registration."
    User(email=email, username=username, password=password).save()
    return True, None


# log in
def fetch_user(email, password):
    u = User.objects(email=email, password=password)
    if len(u) == 0:
        return None
    else:
        return u[0]


def logout_user():
    pass

@@ -362,16 +362,20 @@
 on.%22%0A   
+ u =
  User(em
@@ -426,16 +426,22 @@
 ord)
+%0A    u
 .save()%0A
     
@@ -436,16 +436,48 @@
 .save()%0A
+    u.profile_completed = False%0A
     retu
@@ -674,21 +674,21 @@
 out_user():%0A
-
     pass%0A
@@ -687,8 +687,542 @@
    pass%0A
+%0A%0A# complete user profile%0A# user has already logged in%0A# email, nickname, nationality, location, sex, age, introduction, teach_lan, learn_lan%0Adef update_user(**kwargs)%0A    u = User.objects(email=kwargs%5B'email'%5D)%5B0%5D%0A%0A    u.nickname = kwargs%5B'nickname'%5D%0A    u.nationality = kwargs%5B'nationality'%5D%0A    u.location = kwargs%5B'location'%5D%0A    u.sex = kwargs%5B'sex'%5D%0A    u.age = kwargs%5B'age'%5D%0A    u.introduction = kwargs%5B'introduction'%5D%0A    u.teach_lan = kwargs%5B'teach_lan'%5D%0A    u.learn_lan = kwargs%5B'learn_lan'%5D%0A    u.profile_completed = True%0A%0A

add method update_user