示例#1
0
文件: views.py 项目: jnuthong/Qu-Naer
def register(request):
    """
    Product by J, quality promise
    REQUIRE_PARAM:
        - user_password
        - user_email
        - user_mobile
        - user_nick (this is should be unique)
        - register_ip
        - sex
        - province
        - city
        - district
        - register_ip: maintain var for statistic using, to compute the potential user
    """
    if request.method == "GET":
        return dict(msg="Unexpected request method!",
                    warn="OK")
    else:
        try:
            user_mobile = None
            user_email = None
            # if 'user_mobile' in request.POST.keys():
            #     user_mobile = request.POST.get('user_mobile')
            #
            #     if is_mobile_phone(int(user_mobile)): None
            #     else: return dict(msg="Un-correct format of mobile phone number")
            if "user_email" in request.POST.keys():
                user_email = request.POST.get('user_email')

                if is_email(user_email): None
                else: return dict(msg="Un-correct format of email",
                                  danger="OK")

            city_name = request.POST.get('city_name').encode("utf-8")
            gender = request.POST.get('gender').encode("utf-8")
            password = request.POST.get('user_password').encode("utf-8")
            c_password = request.POST.get('user_confirm_password').encode("utf-8")
            register_ip = get_ip(request)

            # print city_name, gender, password, c_password, register_ip, type(gender)
            if password != c_password:
                return dict(msg="Password is not same!", warn="OK")
            else: password = md5(password)

            return UserProfileLogic.create_user_profile(user_email=user_email,
                                                        city_name=city_name,
                                                        gender=gender,
                                                        password=password,
                                                        register_ip=register_ip)
        except Exception as e:
            print traceback.format_exc()
            return dict(msg="Error occur in user register: %s" % str(e),
                        danger="OK")
示例#2
0
文件: views.py 项目: jnuthong/Qu-Naer
def validEmail(request):
    """
    REQUIRE_PARAM:
        - user_email:
    """
    if request.method == "POST":
        return dict(msg="Unexpected request method!",
                    warn="OK")
    else:
        try:
            user_email = request.GET.get('user_email')
            if is_email(user_email):
                return UserProfileLogic.email_valid_checker_f(user_email)
        except Exception as e:
            return dict(msg="Error in function profile::views::validEmail(), %s" % str(e),
                        warn="OK")
示例#3
0
文件: views.py 项目: jnuthong/Qu-Naer
def activeAccount(request):
    """
    """
    if request.method == "POST":
        return dict(msg="Unexpected request method!",
                    warn="OK")
    else:
        try:
            user_email = request.GET.get('user_email')
            valid_code = request.GET.get('valid_code')
            if is_email(user_email):
                return UserProfileLogic.active_account_f(user_email=user_email,
                                                         valid_code=valid_code)
        except Exception as e:
            return dict(msg="Error in function profile::views::activeAccount(), %s" % str(e),
                        warn="OK")
示例#4
0
def signup(request):
    if not request.session.is_empty():
        return redirect("/home")
    if request.method == "POST":
        user = {'usr': request.POST}
        temp = []
        if utils.is_name(user["usr"].get("name", '')):
            temp.append(True)
        else:
            temp.append(False)
            user[
                "nameError"] = "Please enter Your Legal name and your name should not be greater than 50 Characters."

        if utils.is_email(user["usr"].get("email", '')):
            if User.objects.filter(
                    email=user["usr"].get("email", "")).exists():
                temp.append(False)
                user[
                    "emailError"] = f"{user['usr'].get('email', '')} is already taken."
            else:
                temp.append(True)
        else:
            temp.append(False)
            user["emailError"] = "Please enter valid Email-id."

        if utils.is_strong_password(user["usr"].get("password", '')):
            temp.append(True)
        else:
            temp.append(False)
            user[
                "passwordError"] = "Please create a password greater than or equal to 8."

        if all(temp):
            password = encutils.hash_str(user["usr"].get("password"))
            User.objects.create(name=user["usr"].get("name"),
                                email=user["usr"].get("email"),
                                password=password)
            request.session["name"] = user["usr"].get("name", "")
            request.session["email"] = user["usr"].get("email", "")
            request.session["auth_key"] = encutils.hash_str(
                f"{user['usr']['name']}.{user['usr']['email']}.{password}")

            return redirect("/home")
        return render(request, "signup.html", user)

    return render(request, "signup.html")
示例#5
0
    async def addmanager(self, ctx: commands.Context, *args):
        """
		Add a Google account as a manager of your class's calendar(s)

		Usage:
		```
		++calendar.grant <email>
		```
		If you have more than one class role:
		```
		++calendar.grant <email> <Class Name>
		```
		Arguments:
		**<email>**: Email address to add as a calendar manager.
		**<Class Name>**: The calendar to grant access to (ex. "Lev 2023"). Only necessary if you have more than one class role.
		"""
        # check if calendar was specified
        calendar_match = re.search(r"\b(\w{3} \d{4})", " ".join(args))
        # get calendar
        try:
            calendar_name = calendar_match.groups(
            )[0] if calendar_match else None
            calendar = self.finder.get_calendar(ctx.author, calendar_name)
        except (ClassRoleError, ClassParseError) as error:
            raise FriendlyError(error.args[0], ctx.channel, ctx.author)
        # validate email address
        email = args[0]
        if not is_email(email):
            raise FriendlyError("Invalid email address", ctx.channel,
                                ctx.author)
        # add manager to calendar
        if self.calendar_service.add_manager(calendar.id, email):
            embed = embed_success(
                f":office_worker: Successfully added manager to {calendar.name}."
            )
            await ctx.send(embed=embed)
        else:
            raise FriendlyError("An error occurred while applying changes.",
                                ctx.channel, ctx.author)
示例#6
0
def login(request):
    if not request.session.is_empty():
        return redirect("/home")
    if request.method == "POST":
        user = {"usr": request.POST}
        if utils.is_email(user["usr"].get("email", '')):
            password = encutils.hash_str(user["usr"].get("password", ''))
            usr = User.objects.filter(email=user["usr"].get("email", ''),
                                      password=password)
            if usr.exists():
                request.session["name"] = usr[0].name
                request.session["email"] = usr[0].email
                request.session["auth_key"] = encutils.hash_str(
                    f"{usr[0].name}.{usr[0].email}.{password}")

                return redirect("/home")
            else:
                user["Error"] = "Email-id and password don't match"
        else:
            user["emailError"] = "Please enter valid email-id"
        return render(request, "login.html", user)
    return render(request, "login.html")
 def filter_emails(self, strings: Iterable[str]) -> Set[str]:
     """Given a list of strings returns only those which are email addresses"""
     strings = {s.replace(",", " ").strip() for s in strings}
     return {s for s in strings if is_email(s)}