Exemple #1
0
def after_install():
    # reset installed apps for re-install
    frappe.db.set_global("installed_apps", '["frappe"]')

    install_basic_docs()

    from frappe.core.doctype.file.file import make_home_folder
    make_home_folder()

    import_country_and_currency()

    from frappe.core.doctype.language.language import sync_languages
    sync_languages()

    # save default print setting
    print_settings = frappe.get_doc("Print Settings")
    print_settings.save()

    # all roles to admin
    frappe.get_doc("User", "Administrator").add_roles(
        *frappe.db.sql_list("""select name from tabRole"""))

    # update admin password
    update_password("Administrator", get_admin_password())

    if not frappe.conf.skip_setup_wizard:
        frappe.db.set_default('desktop:home_page', 'setup-wizard')

    # clear test log
    with open(frappe.get_site_path('.test_log'), 'w') as f:
        f.write('')

    add_standard_navbar_items()

    frappe.db.commit()
Exemple #2
0
    def test_hashed_password(self, user='******'):
        old_password = '******'
        new_password = '******'

        update_password(user, new_password)

        auth = frappe.db.sql('''select `password` from `__Auth`
			where doctype='User' and name=%s and fieldname="password"''',
                             user,
                             as_dict=True)[0]

        # is not plain text
        self.assertTrue(auth.password != new_password)

        # is valid hashing
        self.assertTrue(passlibctx.verify(new_password, auth.password))

        self.assertTrue(check_password(user, new_password))

        # revert back to old
        update_password(user, old_password)
        self.assertTrue(check_password(user, old_password))

        # shouldn't work with old password
        self.assertRaises(frappe.AuthenticationError, check_password, user,
                          new_password)
Exemple #3
0
    def test_hashed_password(self, user='******'):
        old_password = '******'
        new_password = '******'

        update_password(user, new_password)

        auth = frappe.db.sql('''select `password`, `salt` from `__Auth`
			where doctype='User' and name=%s and fieldname="password"''',
                             user,
                             as_dict=True)[0]

        self.assertTrue(auth.password != new_password)
        self.assertTrue(auth.salt)

        # stored password = password(plain_text_password + salt)
        self.assertEquals(
            frappe.db.sql('select password(concat(%s, %s))',
                          (new_password, auth.salt))[0][0], auth.password)

        self.assertTrue(check_password(user, new_password))

        # revert back to old
        update_password(user, old_password)
        self.assertTrue(check_password(user, old_password))

        # shouldn't work with old password
        self.assertRaises(frappe.AuthenticationError, check_password, user,
                          new_password)
Exemple #4
0
def add_system_manager(email,
                       first_name=None,
                       last_name=None,
                       send_welcome_email=False,
                       password=None):
    # add user
    user = frappe.new_doc("User")
    user.update({
        "name": email,
        "email": email,
        "enabled": 1,
        "first_name": first_name or email,
        "last_name": last_name,
        "user_type": "System User",
        "send_welcome_email": 1 if send_welcome_email else 0
    })

    user.insert()

    # add roles
    roles = frappe.get_all(
        'Role',
        fields=['name'],
        filters={'name': ['not in', ('Administrator', 'Guest', 'All')]})
    roles = [role.name for role in roles]
    user.add_roles(*roles)

    if password:
        from frappe.utils.password import update_password
        update_password(user=user.name, pwd=password)
Exemple #5
0
def add_system_manager(email,
                       first_name=None,
                       last_name=None,
                       send_welcome_email=False,
                       password=None):
    # add user
    user = frappe.new_doc("User")
    user.update({
        "name": email,
        "email": email,
        "enabled": 1,
        "first_name": first_name or email,
        "last_name": last_name,
        "user_type": "System User",
        "send_welcome_email": 1 if send_welcome_email else 0
    })

    user.insert()

    # add roles
    roles = frappe.db.sql_list("""select name from `tabRole`
		where name not in ("Administrator", "Guest", "All")""")
    user.add_roles(*roles)

    if password:
        from frappe.utils.password import update_password
        update_password(user=user.name, pwd=password)
def update_user_name(args):
	if args.get("email"):
		args['name'] = args.get("email")

		_mute_emails, frappe.flags.mute_emails = frappe.flags.mute_emails, True
		doc = frappe.get_doc({
			"doctype":"User",
			"email": args.get("email"),
			"first_name": args.get("first_name"),
			"last_name": args.get("last_name")
		})
		doc.flags.no_welcome_mail = True
		doc.insert()
		frappe.flags.mute_emails = _mute_emails
		update_password(args.get("email"), args.get("password"))

	else:
		args['name'] = frappe.session.user

		# Update User
		if not args.get('last_name') or args.get('last_name')=='None':
				args['last_name'] = None
		frappe.db.sql("""update `tabUser` SET first_name=%(first_name)s,
			last_name=%(last_name)s WHERE name=%(name)s""", args)

	if args.get("attach_user"):
		attach_user = args.get("attach_user").split(",")
		if len(attach_user)==3:
			filename, filetype, content = attach_user
			fileurl = save_file(filename, content, "User", args.get("name"), decode=True).file_url
			frappe.db.set_value("User", args.get("name"), "user_image", fileurl)

	add_all_roles_to(args.get("name"))
Exemple #7
0
def after_install():
    # reset installed apps for re-install
    frappe.db.set_global("installed_apps", '["frappe"]')

    install_basic_docs()

    from frappe.core.doctype.file.file import make_home_folder
    make_home_folder()

    import_country_and_currency()

    from frappe.core.doctype.language.language import sync_languages
    sync_languages()

    # save default print setting
    print_settings = frappe.get_doc("Print Settings")
    print_settings.save()

    # all roles to admin
    frappe.get_doc("User", "Administrator").add_roles(
        *frappe.db.sql_list("""select name from tabRole"""))

    # update admin password
    update_password("Administrator", get_admin_password())

    # setup wizard now in frappe
    frappe.db.set_default('desktop:home_page', 'setup-wizard')

    frappe.db.commit()
Exemple #8
0
def after_install():
	# reset installed apps for re-install
	frappe.db.set_global("installed_apps", '["frappe"]')

	install_basic_docs()

	from frappe.core.doctype.file.file import make_home_folder
	make_home_folder()

	import_country_and_currency()

	from frappe.core.doctype.language.language import sync_languages
	sync_languages()

	# save default print setting
	print_settings = frappe.get_doc("Print Settings")
	print_settings.save()

	# all roles to admin
	frappe.get_doc("User", "Administrator").add_roles(*frappe.db.sql_list("""select name from tabRole"""))

	# update admin password
	update_password("Administrator", get_admin_password())

	# setup wizard now in frappe
	frappe.db.set_default('desktop:home_page', 'setup-wizard')

	frappe.db.commit()
def reset_pwd_resolver(obj, info: GraphQLResolveInfo, **kwargs):
    user = get_linked_user(id_type=kwargs.get("medium"), id=kwargs.get("medium_id"))
    new_password = kwargs.get("new_password")
    if not user:
        return frappe._dict(status="NO_LINKED_USER")

    user = frappe.get_doc("User", user)
    r = verify_otp(
        medium=kwargs.get("medium"),
        medium_id=kwargs.get("medium_id"),
        otp=kwargs.get("otp"),
        purpose="reset_password"
    )

    if r.status != "verified":
        status = "FAILED"
        if r.status in VERIFY_OTP_STATUS_MAP:
            status = VERIFY_OTP_STATUS_MAP[r.status]

        return frappe._dict(status=status, user=user)

    from frappe.core.doctype.user.user import test_password_strength
    user_data = (user.first_name, user.middle_name,
                 user.last_name, user.email, user.birth_date)
    result = test_password_strength(new_password, '', None, user_data)
    feedback = result.get("feedback", None)

    if feedback and not feedback.get('password_policy_validation_passed', False):
        return frappe._dict(status="WEAK_PASSWORD", user=user)

    update_password(user.name, new_password)
    return frappe._dict(status="SUCCESS", user=user)
Exemple #10
0
def set_password(email, new_password):
    try:
        user_info = frappe.db.sql(
            f"SELECT name FROM tabUser WHERE email='{email}'", as_dict=1)
        name = user_info[0]['name']
        update_password(name, new_password)
        return True
    except:
        return False
Exemple #11
0
def update_quick_login_pin(doc, quick_login_pin):
    if not quick_login_pin:
        return

    update_password(doc.name,
                    quick_login_pin,
                    doctype=doc.doctype,
                    fieldname='quick_login_pin',
                    logout_all_sessions=False)
Exemple #12
0
def update_user_name(args):
    first_name, last_name = args.get("full_name", ""), ""
    if " " in first_name:
        first_name, last_name = first_name.split(" ", 1)

    if args.get("email"):
        if frappe.db.exists("User", args.get("email")):
            # running again
            return

        args["name"] = args.get("email")

        _mute_emails, frappe.flags.mute_emails = frappe.flags.mute_emails, True
        doc = frappe.get_doc({
            "doctype": "User",
            "email": args.get("email"),
            "first_name": first_name,
            "last_name": last_name,
        })
        doc.flags.no_welcome_mail = True
        doc.insert()
        frappe.flags.mute_emails = _mute_emails
        update_password(args.get("email"), args.get("password"))

    elif first_name:
        args.update({
            "name": frappe.session.user,
            "first_name": first_name,
            "last_name": last_name
        })

        frappe.db.sql(
            """update `tabUser` SET first_name=%(first_name)s,
			last_name=%(last_name)s WHERE name=%(name)s""",
            args,
        )

    if args.get("attach_user"):
        attach_user = args.get("attach_user").split(",")
        if len(attach_user) == 3:
            filename, filetype, content = attach_user
            _file = frappe.get_doc({
                "doctype": "File",
                "file_name": filename,
                "attached_to_doctype": "User",
                "attached_to_name": args.get("name"),
                "content": content,
                "decode": True,
            })
            _file.save()
            fileurl = _file.file_url
            frappe.db.set_value("User", args.get("name"), "user_image",
                                fileurl)

    if args.get("name"):
        add_all_roles_to(args.get("name"))
Exemple #13
0
def make_demo_user():
    roles = [
        "Accounts Manager", "Analytics", "Expense Approver", "Accounts User",
        "Leave Approver", "Blogger", "Customer", "Sales Manager", "Employee",
        "HR Manager", "HR User", "Maintenance Manager", "Maintenance User",
        "Stock Manager", "Item Manager", "Stock User", "Manufacturing Manager",
        "Manufacturing User", "Projects User", "Purchase Manager",
        "Purchase Master Manager", "Purchase User", "Quality Manager",
        "Report Manager", "Sales Master Manager", "Sales User", "Supplier",
        "Support Team", "Newsletter Manager"
    ]

    def add_roles(doc):
        for role in roles:
            if not frappe.db.exists("Role", role):
                role_doc = frappe.get_doc({
                    "doctype": "Role",
                    "role_name": role
                })
                role_doc.save()

            doc.append("user_roles", {"doctype": "UserRole", "role": role})

    # make demo user
    if frappe.db.exists("User", "*****@*****.**"):
        frappe.delete_doc("User", "*****@*****.**")

    # add User Type property setter
    user_types = frappe.get_meta("User").get_field("user_type").options
    frappe.make_property_setter({
        "doctype_or_field": "DocField",
        "doctype": "User",
        "fieldname": "user_type",
        "property": "options",
        "value": (user_types or "") + "\nERPNext Demo",
        "property_type": "Text"
    })

    p = frappe.new_doc("User")
    p.email = "*****@*****.**"
    p.first_name = "Demo"
    p.last_name = "User"
    p.enabled = 1
    p.user_type = "ERPNext Demo"
    p.insert()
    add_roles(p)
    p.save()
    update_password("*****@*****.**", "demo")

    # only read for newsletter
    frappe.db.sql("""update `tabDocPerm` set `write`=0, `create`=0, `cancel`=0
		where parent='Newsletter'""")
    frappe.db.sql("""update `tabDocPerm` set `write`=0, `create`=0, `cancel`=0
		where parent='User' and role='All'""")

    frappe.db.commit()
Exemple #14
0
def insert_user(email, first_name, passowrd, last_name=None):
    if not frappe.db.exists("User", email):
        doc = frappe.new_doc("User")
        doc.email = email
        doc.first_name = first_name
        doc.last_name = last_name
        doc.send_welcome_email = 0
        frappe.flags.in_import = True
        doc.insert(ignore_permissions=True)
        frappe.db.commit()
        update_password(user=email, pwd=passowrd)
Exemple #15
0
def _set_user_password(username, password):
    if password is None:
        password = getpass.getpass(
            'Please, enter new password for username {}: '.format(username))
        confirmed_password = getpass.getpass(
            'Confirm new password for username {}: '.format(username))
        if password == confirmed_password:
            update_password(username, password, logout_all_sessions=True)
            frappe.db.commit()
        else:
            print("Confirmed password is not valid")
    else:
        update_password(username, password, logout_all_sessions=True)
        frappe.db.commit()
Exemple #16
0
def update_user_name(args):
    first_name, last_name = args.get('full_name', ''), ''
    if ' ' in first_name:
        first_name, last_name = first_name.split(' ', 1)

    if args.get("email"):
        if frappe.db.exists('User', args.get('email')):
            # running again
            return

        args['name'] = args.get("email")

        _mute_emails, frappe.flags.mute_emails = frappe.flags.mute_emails, True
        doc = frappe.get_doc({
            "doctype": "User",
            "email": args.get("email"),
            "first_name": first_name,
            "last_name": last_name
        })
        doc.flags.no_welcome_mail = True
        doc.insert()
        frappe.flags.mute_emails = _mute_emails
        update_password(args.get("email"), args.get("password"))

    elif first_name:
        args.update({
            "name": frappe.session.user,
            "first_name": first_name,
            "last_name": last_name
        })

        frappe.db.sql(
            """update `tabUser` SET first_name=%(first_name)s,
			last_name=%(last_name)s WHERE name=%(name)s""", args)

    if args.get("attach_user"):
        attach_user = args.get("attach_user").split(",")
        if len(attach_user) == 3:
            filename, filetype, content = attach_user
            fileurl = save_file(filename,
                                content,
                                "User",
                                args.get("name"),
                                decode=True).file_url
            frappe.db.set_value("User", args.get("name"), "user_image",
                                fileurl)

    if args.get('name'):
        add_all_roles_to(args.get("name"))
Exemple #17
0
def set_admin_password(context, admin_password):
	"Set Administrator password for a site"
	import getpass
	from frappe.utils.password import update_password

	for site in context.sites:
		try:
			frappe.init(site=site)

			while not admin_password:
				admin_password = getpass.getpass("Administrator's password for {0}: ".format(site))

			frappe.connect()
			update_password('Administrator', admin_password)
			frappe.db.commit()
			admin_password = None
		finally:
			frappe.destroy()
Exemple #18
0
def set_admin_password(context, admin_password, logout_all_sessions=False):
	"Set Administrator password for a site"
	import getpass
	from frappe.utils.password import update_password

	for site in context.sites:
		try:
			frappe.init(site=site)

			while not admin_password:
				admin_password = getpass.getpass("Administrator's password for {0}: ".format(site))

			frappe.connect()
			update_password(user='******', pwd=admin_password, logout_all_sessions=logout_all_sessions)
			frappe.db.commit()
			admin_password = None
		finally:
			frappe.destroy()
def sign_up(email, full_name, pwd=None, redirect_to=None):
    user = frappe.db.get("User", {"email": email})
    if user:
        if user.disabled:
            return _("Registered but disabled.")
        else:
            return _("Already Registered")
    else:
        if frappe.db.sql("""select count(*) from tabUser where
			HOUR(TIMEDIFF(CURRENT_TIMESTAMP, TIMESTAMP(modified)))=1""")[0][0] > 300:

            frappe.respond_as_web_page(
                _('Temperorily Disabled'),
                _('Too many users signed up recently, so the registration is disabled. Please try back in an hour'
                  ),
                http_status_code=429)

        user = frappe.get_doc({
            "doctype": "User",
            "email": email,
            "first_name": full_name,
            "enabled": 1,
            "user_type": "Website User",
            "send_welcome_email": True
        })

        if pwd:
            user.send_welcome_email = False

        user.flags.ignore_permissions = True
        user.insert()

        if pwd:
            update_password(user.name, pwd)
            frappe.local.login_manager.login_as(email)
            frappe.set_user(email)

        if redirect_to:
            frappe.cache().hset('redirect_after_login', user.name, redirect_to)

        if user.flags.email_sent:
            return _("Please check your email for verification")
        else:
            return _("Please ask your administrator to verify your sign-up")
Exemple #20
0
def update_user_name(args):
	first_name, last_name = args.get('full_name', ''), ''
	if ' ' in first_name:
		first_name, last_name = first_name.split(' ', 1)

	if args.get("email"):
		if frappe.db.exists('User', args.get('email')):
			# running again
			return


		args['name'] = args.get("email")

		_mute_emails, frappe.flags.mute_emails = frappe.flags.mute_emails, True
		doc = frappe.get_doc({
			"doctype":"User",
			"email": args.get("email"),
			"first_name": first_name,
			"last_name": last_name
		})
		doc.flags.no_welcome_mail = True
		doc.insert()
		frappe.flags.mute_emails = _mute_emails
		update_password(args.get("email"), args.get("password"))

	elif first_name:
		args.update({
			"name": frappe.session.user,
			"first_name": first_name,
			"last_name": last_name
		})

		frappe.db.sql("""update `tabUser` SET first_name=%(first_name)s,
			last_name=%(last_name)s WHERE name=%(name)s""", args)

	if args.get("attach_user"):
		attach_user = args.get("attach_user").split(",")
		if len(attach_user)==3:
			filename, filetype, content = attach_user
			fileurl = save_file(filename, content, "User", args.get("name"), decode=True).file_url
			frappe.db.set_value("User", args.get("name"), "user_image", fileurl)

	if args.get('name'):
		add_all_roles_to(args.get("name"))
Exemple #21
0
def generate_user(student, password="******"):
    student_profile = get_student_profile()
    user_doc = {
        "doctype": "User",
        "email": student.student_email_id,
        "user_type": "Website User",
        "first_name": student.first_name,
        "middle_name": student.middle_name,
        "last_name": student.last_name,
        "mobile_no": student.student_mobile_number,
        "birth_date": student.date_of_birth,
        "role_profile_name": student_profile
    }
    user = frappe.get_doc(user_doc)
    try:
        user.insert()
    except:
        throw(_("Error while validating new User"))
    else:
        update_password(user=user.name, pwd=password)
Exemple #22
0
def set_admin_password(context, admin_password, logout_all_sessions=False):
	"Set Administrator password for a site"
	import getpass
	from frappe.utils.password import update_password

	for site in context.sites:
		try:
			frappe.init(site=site)

			while not admin_password:
				admin_password = getpass.getpass("Administrator's password for {0}: ".format(site))

			frappe.connect()
			update_password(user='******', pwd=admin_password, logout_all_sessions=logout_all_sessions)
			frappe.db.commit()
			admin_password = None
		finally:
			frappe.destroy()
	if not context.sites:
		raise SiteNotSpecifiedError
Exemple #23
0
def change_password(old_password, new_password):
  """
  Update the password when old password is given
  :param old_password: The old password of the User
  :param new_password: The new password to set for the user
  """
  from frappe.core.doctype.user.user import test_password_strength, handle_password_test_fail

  check_password(user=frappe.session.user, pwd=old_password)

  user = frappe.get_doc("User", frappe.session.user)
  user_data = (user.first_name, user.middle_name,
               user.last_name, user.email, user.birth_date)
  result = test_password_strength(new_password, '', None, user_data)
  feedback = result.get("feedback", None)

  if feedback and not feedback.get('password_policy_validation_passed', False):
    handle_password_test_fail(result)

  update_password(user.name, new_password)
  return True
Exemple #24
0
def set_user_password(site, user, password, logout_all_sessions=False):
    import getpass
    from frappe.utils.password import update_password

    try:
        frappe.init(site=site)

        while not password:
            password = getpass.getpass(f"{user}'s password for {site}: ")

        frappe.connect()
        if not frappe.db.exists("User", user):
            print(f"User {user} does not exist")
            sys.exit(1)

        update_password(user=user,
                        pwd=password,
                        logout_all_sessions=logout_all_sessions)
        frappe.db.commit()
        password = None
    finally:
        frappe.destroy()
Exemple #25
0
	def test_hashed_password(self, user='******'):
		old_password = '******'
		new_password = '******'

		update_password(user, new_password)

		auth = get_password_list(dict(doctype='User', name=user))[0]

		# is not plain text
		self.assertTrue(auth.password != new_password)

		# is valid hashing
		self.assertTrue(passlibctx.verify(new_password, auth.password))

		self.assertTrue(check_password(user, new_password))

		# revert back to old
		update_password(user, old_password)
		self.assertTrue(check_password(user, old_password))

		# shouldn't work with old password
		self.assertRaises(frappe.AuthenticationError, check_password, user, new_password)
Exemple #26
0
	def test_hashed_password(self, user='******'):
		old_password = '******'
		new_password = '******'

		update_password(user, new_password)

		auth = frappe.db.sql('''select `password`, `salt` from `__Auth`
			where doctype='User' and name=%s and fieldname="password"''', user, as_dict=True)[0]

		self.assertTrue(auth.password != new_password)
		self.assertTrue(auth.salt)

		# stored password = password(plain_text_password + salt)
		self.assertEquals(frappe.db.sql('select password(concat(%s, %s))', (new_password, auth.salt))[0][0], auth.password)

		self.assertTrue(check_password(user, new_password))

		# revert back to old
		update_password(user, old_password)
		self.assertTrue(check_password(user, old_password))

		# shouldn't work with old password
		self.assertRaises(frappe.AuthenticationError, check_password, user, new_password)
Exemple #27
0
	def test_hashed_password(self, user='******'):
		old_password = '******'
		new_password = '******'

		update_password(user, new_password)

		auth = frappe.db.sql('''select `password` from `__Auth`
			where doctype='User' and name=%s and fieldname="password"''', user, as_dict=True)[0]

		# is not plain text
		self.assertTrue(auth.password != new_password)

		# is valid hashing
		self.assertTrue(passlibctx.verify(new_password, auth.password))

		self.assertTrue(check_password(user, new_password))

		# revert back to old
		update_password(user, old_password)
		self.assertTrue(check_password(user, old_password))

		# shouldn't work with old password
		self.assertRaises(frappe.AuthenticationError, check_password, user, new_password)
Exemple #28
0
def add_system_manager(email, first_name=None, last_name=None, send_welcome_email=False, password=None):
	# add user
	user = frappe.new_doc("User")
	user.update({
		"name": email,
		"email": email,
		"enabled": 1,
		"first_name": first_name or email,
		"last_name": last_name,
		"user_type": "System User",
		"send_welcome_email": 1 if send_welcome_email else 0
	})

	user.insert()

	# add roles
	roles = frappe.db.sql_list("""select name from `tabRole`
		where name not in ("Administrator", "Guest", "All")""")
	user.add_roles(*roles)

	if password:
		from frappe.utils.password import update_password
		update_password(user=user.name, pwd=password)
Exemple #29
0
def create_account_college(first_name,
                           last_name,
                           id_number,
                           contact_number,
                           url,
                           welcome_text,
                           programs,
                           courses,
                           grade_level,
                           school_year,
                           reset_pass=0):

    code = random_word(8)

    import ast
    print("((( XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX )))")
    print(programs, courses)
    programs = ast.literal_eval(programs)
    courses = ast.literal_eval(courses)
    # x = [n.strip() for n in x]

    programs_ = []

    # courses_ = []

    for prog in programs:
        cours = prog
        cours = cours.replace("/", " ")
        cours = cours.replace("-", " ")
        cours = cours.replace("&", "and")
        cours = cours.replace("*", "")
        cours = cours.replace(":", "")
        cours = cours.replace(",", "")
        cours = cours.replace(".", "")

        # program does not allow special characters
        prog = prog.replace("/", " ")
        prog = prog.replace("-", " ")
        prog = prog.replace("&", "and")
        prog = prog.replace("(", "")
        prog = prog.replace(")", "")
        prog = prog.replace("*", "")
        prog = prog.replace(":", "")
        prog = prog.replace(",", "")
        prog = prog.replace(".", "")

        programs_.append({"program": prog, "course": cours})

    if not frappe.db.exists('User', id_number + "@wela.online"):

        user = frappe.get_doc({
            "doctype": "User",
            "first_name": first_name,
            "last_name": last_name,
            "username": id_number,
            "email": id_number + "@wela.online",
            "user_type": "System User",
            "send_welcome_email": 0
        }).insert(ignore_permissions=True)

        user.append('roles', {"doctype": "Has Role", "role": "Student"})

        for d in user.block_modules:
            user.block_modules.remove(d)

        block_mods = [
            'Desk', 'Users and Permissions', 'Integrations', 'Social',
            'dashboard', 'Accounts', 'Buying', 'Assets', 'CRM', 'HR',
            'Marketplace', 'Settings', 'Customization', 'Website',
            'Leaderboard', 'Getting Started', 'Selling', 'Stock', 'Projects',
            'Support', 'Quality Management', 'Help', 'Program Enrollment Tool',
            'Quiz Activity'
        ]

        for mod in block_mods:
            user.append("block_modules", {'module': mod})

        user.save()

        frappe.db.commit()

        # code = random_word(8)

        # message =  "Your WELA account, username:{0}@wela.online, password: {1}. " \
        #            "Website: {2}".format(id_number, code, url)

        # message = "After done paying. Proceed with your Online Class, log on to {2} , " \
        #           "username:{0}@wela.online, password: {1}. ".format(id_number, code, url)

        # message = welcome_text.format(id_number, code, url)

        # send_to_semaphore(contact_number, message)
        update_password(user.name, code)

        user.save()

        frappe.db.commit()

        student = frappe.get_doc({
            "doctype": "Student",
            "first_name": first_name,
            "last_name": last_name,
            "student_email_id": id_number + "@wela.online",
            "user": user.name,
            "grade_level": grade_level,
            # "note":note,
            # "entrance_exam":entrance_exam
        }).insert(ignore_permissions=True)

        frappe.db.commit()

        for cours in programs_:

            exists_program = frappe.db.sql(
                """SELECT name FROM `tabCourse`
                                                                        WHERE course_name=%s""",
                (cours['course']))

            if exists_program == ():
                course_doc = frappe.get_doc({
                    "doctype": "Course",
                    "course_name": cours['course']
                }).insert(ignore_permissions=True)
                frappe.db.commit()

        for prog in programs_:

            exists_program = frappe.db.sql(
                """SELECT name FROM `tabProgram`
                                                                 WHERE program_name=%s""",
                (prog['program']))

            if exists_program == ():
                program_doc = frappe.get_doc({
                    "doctype":
                    "Program",
                    "program_name":
                    prog['program'],
                    "is_published":
                    1,
                    "courses": [{
                        "course": prog['course'],
                        "course_name": prog['course']
                    }]
                }).insert(ignore_permissions=True)
                frappe.db.commit()

        exists_program = frappe.db.sql(
            """SELECT name FROM `tabAcademic Year`
                                                                           WHERE academic_year_name=%s""",
            (school_year))

        if exists_program == ():
            course_doc = frappe.get_doc({
                "doctype": "Academic Year",
                "academic_year_name": school_year
            }).insert(ignore_permissions=True)
            frappe.db.commit()

        for i, prog in enumerate(programs_):
            enrollment = frappe.get_doc({
                "doctype":
                "Program Enrollment",
                "student":
                student.name,
                "academic_year":
                school_year,
                "program":
                prog['program'],
                "enrollment_date":
                frappe.utils.get_datetime().date(),
                "docstatus":
                1
            }).insert(ignore_permissions=True)
            frappe.db.commit()

            course_enrollment = frappe.get_doc({
                "doctype":
                "Course Enrollment",
                "student":
                student.name,
                # "academic_year": "2020-21",
                "program_enrollment":
                enrollment.name,
                "course":
                prog['course'],
                "enrollment_date":
                frappe.utils.get_datetime().date(),
                # "docstatus": 1
            }).insert(ignore_permissions=True)

    else:

        user = frappe.get_doc("User", id_number + "@wela.online")

        # import ast
        # print("((( XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX )))")
        # print(programs, courses)
        # programs = ast.literal_eval(programs)
        # courses = ast.literal_eval(courses)

        student_sql = frappe.db.sql(
            """select name from `tabStudent` where student_email_id=%s""",
            (id_number + "@wela.online"))

        print(school_year)
        if student_sql != ():
            student = frappe.get_doc("Student", student_sql[0][0])
        else:
            student = frappe.get_doc({
                "doctype": "Student",
                "first_name": first_name,
                "last_name": last_name,
                "student_email_id": id_number + "@wela.online",
                "user": user.name,
                "grade_level": grade_level,
                # "note":note,
                # "entrance_exam":entrance_exam
            }).insert(ignore_permissions=True)
            frappe.db.commit()

        # if reset_pass == 1:
        # code = random_word(8)
        # message = welcome_text.format(id_number, code, url)

        # send_to_semaphore(contact_number, message)
        update_password(user.name, code)

        user.save()

        for cours in programs_:

            exists_program = frappe.db.sql(
                """SELECT name FROM `tabCourse`
                                                                              WHERE course_name=%s""",
                (cours['course']))

            if exists_program == ():
                course_doc = frappe.get_doc({
                    "doctype": "Course",
                    "course_name": cours['course']
                }).insert(ignore_permissions=True)
                frappe.db.commit()

        for prog in programs_:

            exists_program = frappe.db.sql(
                """SELECT name FROM `tabProgram`
                                                                 WHERE program_name=%s""",
                (prog['program']))

            if exists_program == ():
                print(prog)
                program_doc = frappe.get_doc({
                    "doctype":
                    "Program",
                    "program_name":
                    prog['program'],
                    "is_published":
                    1,
                    "courses": [{
                        "course": prog['course'],
                        "course_name": prog['course']
                    }]
                }).insert(ignore_permissions=True)
                frappe.db.commit()

        exists_program = frappe.db.sql(
            """SELECT name FROM `tabAcademic Year`
                                                                                 WHERE academic_year_name=%s""",
            (school_year))

        if exists_program == ():
            course_doc = frappe.get_doc({
                "doctype": "Academic Year",
                "academic_year_name": school_year
            }).insert(ignore_permissions=True)
            frappe.db.commit()

        for i, prog in enumerate(programs_):

            exists_program = frappe.db.sql(
                """SELECT name FROM `tabProgram Enrollment`
                                                WHERE program=%s 
                                        and student=%s and docstatus=1""",
                (prog['program'], student.name))

            if exists_program == ():

                try:
                    enrollment = frappe.get_doc({
                        "doctype":
                        "Program Enrollment",
                        "student":
                        student.name,
                        "academic_year":
                        school_year,
                        "program":
                        prog['program'],
                        "enrollment_date":
                        frappe.utils.get_datetime().date(),
                        "docstatus":
                        1
                    }).insert(ignore_permissions=True)
                    frappe.db.commit()

                    course_enrollment = frappe.get_doc({
                        "doctype":
                        "Course Enrollment",
                        "student":
                        student.name,
                        # "academic_year": "2020-21",
                        "program_enrollment":
                        enrollment.name,
                        "course":
                        prog['course'],
                        "enrollment_date":
                        frappe.utils.get_datetime().date(),
                        # "docstatus": 1
                    }).insert(ignore_permissions=True)
                except:
                    pass

    from lms_api.lms_api.college import create_rooms_and_permissions

    try:
        create_rooms_and_permissions(user.name)
    except:
        pass

    return user.name, code
Exemple #30
0
def create_account_(name, school_year='SY2020-2021', branch=""):

    student = frappe.get_doc("Student", name)

    print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")

    print(student.first_name, student.last_name, student.user)

    if student.user:

        user = frappe.get_doc("User", student.user)

    else:
        user = frappe.get_doc({
            "doctype":
            "User",
            "first_name":
            student.first_name.strip(),
            "last_name":
            student.last_name.strip(),
            "username":
            student.last_name.strip().replace(" ", "") +
            student.first_name.strip().replace(" ", "") + "@wela.online",
            "email":
            student.last_name.strip().replace(" ", "") +
            student.first_name.strip().replace(" ", "") + "@wela.online",
            # "mobile_no":contact_number,
            "user_type":
            "System User",
            "send_welcome_email":
            0
        }).insert(ignore_permissions=True)

        frappe.db.commit()

        student.user = user.name
        student.email_id = user.name

    user.append('roles', {"doctype": "Has Role", "role": "Student"})

    for d in user.block_modules:
        user.block_modules.remove(d)

    block_mods = [
        'Desk', 'Users and Permissions', 'Integrations', 'dashboard',
        'Accounts', 'Buying', 'Assets', 'CRM', 'HR', 'Marketplace', 'Settings',
        'Customization', 'Website', 'Leaderboard', 'Getting Started',
        'Selling', 'Stock', 'Projects', 'Support', 'Quality Management',
        'Help', 'Program Enrollment Tool', 'Quiz Activity'
    ]

    for mod in block_mods:
        user.append("block_modules", {'module': mod})

    user.save()

    frappe.db.commit()

    code = random_word(8)

    update_password(user.name, code)

    welcome_text = "Your WELA account, username:{0}, password: {1}. " \
                   "Website: tecarro.silid.co".format(user.name, code)

    send_to_semaphore(student.student_mobile_number, welcome_text)

    exists_program = frappe.db.sql(
        """SELECT name FROM `tabAcademic Year`
                                                                       WHERE academic_year_name=%s""",
        (school_year))

    if exists_program == ():
        course_doc = frappe.get_doc({
            "doctype": "Academic Year",
            "academic_year_name": school_year
        }).insert(ignore_permissions=True)
        frappe.db.commit()

    try:
        enrollment = frappe.get_doc({
            "doctype":
            "Program Enrollment",
            "student":
            student.name,
            "academic_year":
            school_year,
            "program":
            student.program,
            "enrollment_date":
            frappe.utils.get_datetime().date(),
        }).insert(ignore_permissions=True)

        enrollment.submit()
    except Exception as e:
        print(e)
        pass

    return user.name
Exemple #31
0
def setup_users():
    print("Users Setup...")

    frappe.get_doc("User", "*****@*****.**").hide_modules()

    try:
        portal_user = frappe.get_doc({
            "email": "*****@*****.**",
            "first_name": "Francis",
            "last_name": "Charpentier",
            "language": "fr",
            "doctype": "User",
            "send_welcome_email": 0
        })
        portal_user.insert()
        portal_user.add_roles("Customer")
        portal_user.add_roles("Volunteer")
        update_password(portal_user.name, "tierslieux")
    except frappe.DuplicateEntryError:
        pass

    employees = [{
        "email": "*****@*****.**",
        "first_name": "Tilly",
        "last_name": "LaCaille",
        "language": "fr",
        "doctype": "User",
        "send_welcome_email": 0,
        "new_password": "******"
    }, {
        "email": "*****@*****.**",
        "first_name": "Alfred",
        "last_name": "Faubert",
        "language": "fr",
        "doctype": "User",
        "send_welcome_email": 0,
        "new_password": "******"
    }, {
        "email": "*****@*****.**",
        "first_name": "Huette",
        "last_name": "Fortier",
        "language": "fr",
        "doctype": "User",
        "send_welcome_email": 0,
        "new_password": "******"
    }, {
        "email": "*****@*****.**",
        "first_name": "Agnès",
        "last_name": "Pomerleau",
        "language": "fr",
        "doctype": "User",
        "send_welcome_email": 0,
        "new_password": "******"
    }]
    for employee in employees:
        try:
            user = frappe.get_doc(employee)
            user.insert()
            user.add_roles("Employee")
            update_password(user.name, "tierslieux")
        except frappe.DuplicateEntryError:
            continue

    frappe.db.commit()
Exemple #32
0
def create_account_(first_name, last_name, id_number, contact_number, url,
                    welcome_text, programs, courses, grade_level, school_year):
    if not frappe.db.exists('User', id_number + "@wela.online"):

        import ast
        print("((( XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX )))")
        print(programs, courses)
        programs = ast.literal_eval(programs)
        courses = ast.literal_eval(courses)
        # x = [n.strip() for n in x]

        user = frappe.get_doc({
            "doctype": "User",
            "first_name": first_name,
            "last_name": last_name,
            "username": id_number,
            "email": id_number + "@wela.online",
            "user_type": "System User",
            "send_welcome_email": 0
        }).insert(ignore_permissions=True)

        user.append('roles', {"doctype": "Has Role", "role": "Student"})

        for d in user.block_modules:
            user.block_modules.remove(d)

        block_mods = [
            'Desk', 'Users and Permissions', 'Integrations', 'dashboard',
            'Accounts', 'Buying', 'Assets', 'CRM', 'HR', 'Marketplace',
            'Settings', 'Customization', 'Website', 'Leaderboard',
            'Getting Started', 'Selling', 'Stock', 'Projects', 'Support',
            'Quality Management', 'Help', 'Program Enrollment Tool',
            'Quiz Activity'
        ]

        for mod in block_mods:
            user.append("block_modules", {'module': mod})

        user.save()

        frappe.db.commit()

        code = random_word(8)

        # message =  "Your WELA account, username:{0}@wela.online, password: {1}. " \
        #            "Website: {2}".format(id_number, code, url)

        # message = "After done paying. Proceed with your Online Class, log on to {2} , " \
        #           "username:{0}@wela.online, password: {1}. ".format(id_number, code, url)

        message = welcome_text.format(id_number, code, url)

        # send_to_semaphore(contact_number, message)

        # self.send_account_details = 0

        # user.new_password = self.default_code
        # user.save()
        # /home/jvfiel/frappe-v11/apps/frappe/frappe/utils/password.py
        # print("************ UPDATE PASSWORD ************")
        # print(user.name,code)

        if not frappe.db.exists('Year Level', grade_level):
            lvl = frappe.get_doc({
                "doctype": "Year Level",
                "level": grade_level
            }).insert(ignore_permissions=True)
            frappe.db.commit()

        update_password(user.name, code)

        student = frappe.get_doc({
            "doctype": "Student",
            "first_name": first_name,
            "last_name": last_name,
            "student_email_id": id_number + "@wela.online",
            "user": user.name,
            "level": grade_level
            # "note":note,
            # "entrance_exam":entrance_exam
        }).insert(ignore_permissions=True)

        frappe.db.commit()

        # for cours in courses:
        #     exists_program = frappe.db.sql("""SELECT name FROM `tabCourse`
        #                                                                 WHERE course_name=%s""", (cours))
        #
        #     if exists_program == ():
        #         course_doc = frappe.get_doc({
        #             "doctype": "Course",
        #             "course_name": cours
        #         }).insert(ignore_permissions=True)
        #         frappe.db.commit()
        #
        #
        #
        #
        # for prog in programs:
        #     exists_program = frappe.db.sql("""SELECT name FROM `tabProgram`
        #                                                          WHERE program_name=%s""",(prog))
        #
        #     if exists_program == ():
        #         program_doc = frappe.get_doc({
        #             "doctype": "Program",
        #             "program_name": prog,
        #             "is_published":1,
        #             "courses":[{"course":prog,"course_name":prog}]
        #         }).insert(ignore_permissions=True)
        #         frappe.db.commit()

        exists_program = frappe.db.sql(
            """SELECT name FROM `tabAcademic Year`
                                                                           WHERE academic_year_name=%s""",
            (school_year))

        if exists_program == ():
            course_doc = frappe.get_doc({
                "doctype": "Academic Year",
                "academic_year_name": school_year
            }).insert(ignore_permissions=True)
            frappe.db.commit()

        # for i,prog in enumerate(programs):
        #     enrollment = frappe.get_doc({
        #         "doctype": "Program Enrollment",
        #         "student": student.name,
        #         "academic_year": school_year,
        #         "program": prog,
        #         "enrollment_date": frappe.utils.get_datetime().date(),
        #         "docstatus": 1
        #     }).insert(ignore_permissions=True)
        #     frappe.db.commit()
        #
        #
        #     course_enrollment = frappe.get_doc({
        #         "doctype": "Course Enrollment",
        #         "student": student.name,
        #         # "academic_year": "2020-21",
        #         "program_enrollment": enrollment.name,
        #         "course": courses[i],
        #         "enrollment_date": frappe.utils.get_datetime().date(),
        #         # "docstatus": 1
        #     }).insert(ignore_permissions=True)

    else:

        user = frappe.get_doc("User", id_number + "@wela.online")

        code = random_word(8)

        # message =  "Your WELA account, username:{0}@wela.online, password: {1}. " \
        #            "Website: {2}".format(id_number, code, url)

        # message = "After done paying. Proceed with your Online Class, log on to {2} , " \
        #           "username:{0}@wela.online, password: {1}. ".format(id_number, code, url)

        message = welcome_text.format(id_number, code, url)

        # send_to_semaphore(contact_number, message)

        # self.send_account_details = 0

        # user.new_password = self.default_code
        # user.save()
        # /home/jvfiel/frappe-v11/apps/frappe/frappe/utils/password.py
        # print("************ UPDATE PASSWORD ************")
        # print(user.name,code)
        update_password(user.name, code)

        user.save()
        # for cours in courses:
        #     print(cours)
        #     if cours:
        #         exists_program = frappe.db.sql("""SELECT name FROM `tabCourse`
        #                                                                     WHERE course_name=%s""", (cours))
        #
        #         if exists_program == ():
        #             course_doc = frappe.get_doc({
        #                 "doctype": "Course",
        #                 "course_name": cours
        #             }).insert(ignore_permissions=True)
        #             frappe.db.commit()
        #
        #
        #
        #
        # for prog in programs:
        #     exists_program = frappe.db.sql("""SELECT name FROM `tabProgram`
        #                                                          WHERE program_name=%s""",(prog))
        #
        #     if exists_program == ():
        #         program_doc = frappe.get_doc({
        #             "doctype": "Program",
        #             "program_name": prog,
        #             "is_published":1,
        #             "courses":[{"course":prog,"course_name":prog}]
        #         }).insert(ignore_permissions=True)
        #         frappe.db.commit()
        #
        #
        #
        #
        # exists_program = frappe.db.sql("""SELECT name FROM `tabAcademic Year`
        #                                                                    WHERE academic_year_name=%s""", (school_year))
        #
        # if exists_program == ():
        #     course_doc = frappe.get_doc({
        #         "doctype": "Academic Year",
        #         "academic_year_name": school_year
        #     }).insert(ignore_permissions=True)
        #     frappe.db.commit()
        #     print('school year created!')
        # else:
        #     print('exists sy')
        #     print(exists_program)
        #
        # # student = frappe.get_doc({
        # #     "doctype": "Student",
        # #     "first_name": first_name,
        # #     "last_name": last_name,
        # #     "student_email_id": id_number + "@wela.online",
        # #     "user": user.name,
        # #     "grade_level": grade_level,
        # #     # "note":note,
        # #     # "entrance_exam":entrance_exam
        # # }).insert(ignore_permissions=True)
        #
        # student_sql = frappe.db.sql("""select name from `tabStudent` where student_email_id=%s""",(id_number + "@wela.online"))
        #
        #
        # print(school_year)
        # if student_sql != ():
        #     student = frappe.get_doc("Student",student_sql[0][0])
        #
        #     for i,prog in enumerate(programs):
        #
        #         try:
        #             enrollment = frappe.get_doc({
        #                 "doctype": "Program Enrollment",
        #                 "student": student.name,
        #                 "academic_year": school_year,
        #                 "program": prog,
        #                 "enrollment_date": frappe.utils.get_datetime().date(),
        #                 "docstatus": 1
        #             }).insert(ignore_permissions=True)
        #             frappe.db.commit()
        #
        #
        #             course_enrollment = frappe.get_doc({
        #                 "doctype": "Course Enrollment",
        #                 "student": student.name,
        #                 # "academic_year": "2020-21",
        #                 "program_enrollment": enrollment.name,
        #                 "course": courses[i],
        #                 "enrollment_date": frappe.utils.get_datetime().date(),
        #                 # "docstatus": 1
        #             }).insert(ignore_permissions=True)
        #         except:
        #             pass

    return user.name, code
Exemple #33
0
def create_account_resend(first_name,
                          last_name,
                          id_number,
                          contact_number,
                          url,
                          welcome_text,
                          programs,
                          courses,
                          grade_level,
                          school_year,
                          branch=""):
    if not frappe.db.exists('User', id_number + "@wela.online"):

        import ast
        print("((( XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX )))")
        print(programs, courses)
        programs = ast.literal_eval(programs)
        courses = ast.literal_eval(courses)
        # x = [n.strip() for n in x]

        user = frappe.get_doc({
            "doctype": "User",
            "first_name": first_name,
            "last_name": last_name,
            "username": id_number,
            "email": id_number + "@wela.online",
            # "mobile_no":contact_number,
            "user_type": "System User",
            "send_welcome_email": 0
        }).insert(ignore_permissions=True)

        user.append('roles', {"doctype": "Has Role", "role": "Student"})

        for d in user.block_modules:
            user.block_modules.remove(d)

        block_mods = [
            'Desk', 'Users and Permissions', 'Integrations', 'dashboard',
            'Accounts', 'Buying', 'Assets', 'CRM', 'HR', 'Marketplace',
            'Settings', 'Customization', 'Website', 'Leaderboard',
            'Getting Started', 'Selling', 'Stock', 'Projects', 'Support',
            'Quality Management', 'Help', 'Program Enrollment Tool',
            'Quiz Activity'
        ]

        for mod in block_mods:
            user.append("block_modules", {'module': mod})

        user.save()

        frappe.db.commit()

        code = random_word(8)
        message = welcome_text.format(id_number, code, url)

        send_to_semaphore(contact_number, message)
        if not frappe.db.exists('Year Level', grade_level):
            lvl = frappe.get_doc({
                "doctype": "Year Level",
                "level": grade_level
            }).insert(ignore_permissions=True)
            frappe.db.commit()

        update_password(user.name, code)
        if branch:
            if not frappe.db.exists('Branch', branch):
                create_branch = frappe.get_doc({
                    "doctype": "Branch",
                    "branch": branch
                }).insert(ignore_permissions=True)
                frappe.db.commit()
            student = frappe.get_doc({
                "doctype": "Student",
                "first_name": first_name,
                "last_name": last_name,
                "student_email_id": id_number + "@wela.online",
                "user": user.name,
                "level": grade_level,
                "student_mobile_number": contact_number,
                "branch": branch
                # "note":note,
                # "entrance_exam":entrance_exam
            }).insert(ignore_permissions=True)
        else:
            student = frappe.get_doc({
                "doctype": "Student",
                "first_name": first_name,
                "last_name": last_name,
                "student_email_id": id_number + "@wela.online",
                "user": user.name,
                "level": grade_level,
                "student_mobile_number": contact_number,
                # "note":note,
                # "entrance_exam":entrance_exam
            }).insert(ignore_permissions=True)

        frappe.db.commit()

        exists_program = frappe.db.sql(
            """SELECT name FROM `tabAcademic Year`
                                                                           WHERE academic_year_name=%s""",
            (school_year))

        if exists_program == ():
            course_doc = frappe.get_doc({
                "doctype": "Academic Year",
                "academic_year_name": school_year
            }).insert(ignore_permissions=True)
            frappe.db.commit()

        # for i,prog in enumerate(programs):
        #     enrollment = frappe.get_doc({
        #         "doctype": "Program Enrollment",
        #         "student": student.name,
        #         "academic_year": school_year,
        #         "program": prog,
        #         "enrollment_date": frappe.utils.get_datetime().date(),
        #         "docstatus": 1
        #     }).insert(ignore_permissions=True)
        #     frappe.db.commit()
        #
        #
        #     course_enrollment = frappe.get_doc({
        #         "doctype": "Course Enrollment",
        #         "student": student.name,
        #         # "academic_year": "2020-21",
        #         "program_enrollment": enrollment.name,
        #         "course": courses[i],
        #         "enrollment_date": frappe.utils.get_datetime().date(),
        #         # "docstatus": 1
        #     }).insert(ignore_permissions=True)

    else:

        user = frappe.get_doc("User", id_number + "@wela.online")

        student = frappe.db.sql(
            """select name from `tabStudent` where student_email_id=%s""",
            (id_number + "@wela.online"))
        if student != ():
            """

                "level":grade_level,
            "student_mobile_number":contact_number

            """
            if branch:
                if not frappe.db.exists('Branch', branch):
                    create_branch = frappe.get_doc({
                        "doctype": "Branch",
                        "branch": branch
                    }).insert(ignore_permissions=True)
                    frappe.db.commit()

            stud = frappe.get_doc("Student", student[0][0])
            stud.level = grade_level
            stud.student_mobile_number = contact_number
            if branch:
                stud.branch = branch
            stud.save()

        else:
            try:
                if branch:
                    if not frappe.db.exists('Branch', branch):
                        create_branch = frappe.get_doc({
                            "doctype": "Branch",
                            "branch": branch
                        }).insert(ignore_permissions=True)
                        frappe.db.commit()
                    student = frappe.get_doc({
                        "doctype": "Student",
                        "first_name": first_name,
                        "last_name": last_name,
                        "student_email_id": id_number + "@wela.online",
                        "user": id_number + "@wela.online",
                        "level": grade_level,
                        "student_mobile_number": contact_number,
                        "branch": branch
                    }).insert(ignore_permissions=True)
                else:
                    student = frappe.get_doc({
                        "doctype":
                        "Student",
                        "first_name":
                        first_name,
                        "last_name":
                        last_name,
                        "student_email_id":
                        id_number + "@wela.online",
                        "user":
                        id_number + "@wela.online",
                        "level":
                        grade_level,
                        "student_mobile_number":
                        contact_number,
                    }).insert(ignore_permissions=True)

                frappe.db.commit()
            except:
                pass

    return user.name
Exemple #34
0
def create_account(first_name,
                   last_name,
                   id_number,
                   contact_number,
                   url,
                   welcome_text,
                   grade_level="",
                   note="",
                   school_year="",
                   entrance_exam=""):
    if not frappe.db.exists('User', id_number + "@wela.online"):
        user = frappe.get_doc({
            "doctype": "User",
            "first_name": first_name,
            "last_name": last_name,
            "username": id_number,
            "email": id_number + "@wela.online",
            "user_type": "System User",
            "send_welcome_email": 0
        }).insert(ignore_permissions=True)

        user.append('roles', {"doctype": "Has Role", "role": "Student"})

        for d in user.block_modules:
            user.block_modules.remove(d)

        block_mods = [
            'Desk', 'Users and Permissions', 'Integrations', 'Social',
            'dashboard', 'Accounts', 'Buying', 'Assets', 'CRM', 'HR',
            'Marketplace', 'Settings', 'Customization', 'Website',
            'Leaderboard', 'Getting Started', 'Selling', 'Stock', 'Projects',
            'Support', 'Quality Management', 'Help', 'Program Enrollment Tool',
            'Quiz Activity'
        ]

        for mod in block_mods:
            user.append("block_modules", {'module': mod})

        user.save()

        frappe.db.commit()

        code = random_word(8)

        # message =  "Your WELA account, username:{0}@wela.online, password: {1}. " \
        #            "Website: {2}".format(id_number, code, url)

        # message = "After done paying. Proceed with your Online Class, log on to {2} , " \
        #           "username:{0}@wela.online, password: {1}. ".format(id_number, code, url)

        message = welcome_text.format(id_number, code, url)

        send_to_semaphore(contact_number, message)
        # self.send_account_details = 0

        # user.new_password = self.default_code
        # user.save()
        # /home/jvfiel/frappe-v11/apps/frappe/frappe/utils/password.py

        # print("************ UPDATE PASSWORD ************")
        # print(user.name,code)
        update_password(user.name, code)

        student = frappe.get_doc({
            "doctype": "Student",
            "first_name": first_name,
            "last_name": last_name,
            "student_email_id": id_number + "@wela.online",
            "user": user.name,
            "grade_level": grade_level,
            "note": note,
            "entrance_exam": entrance_exam
        }).insert(ignore_permissions=True)

        frappe.db.commit()
        if note == "Summer":

            exists_program = frappe.db.sql("""SELECT Count(*) FROM `tabProgram`
                                                        WHERE program_name='Summer Class Applicants'"""
                                           )

            if exists_program == ():
                program = frappe.get_doc({
                    "doctype":
                    "Program",
                    "program_name":
                    "Summer Class Applicants"
                }).insert(ignore_permissions=True)

            program = frappe.get_doc({
                "doctype":
                "Program Enrollment",
                "student":
                student.name,
                "academic_year":
                "2020 Summer",
                "program":
                "Summer Class Applicants",
                "enrollment_date":
                frappe.utils.get_datetime().date(),
                "docstatus":
                1
            }).insert(ignore_permissions=True)
        elif note == "Exam":

            exists_program = frappe.db.sql("""SELECT Count(*) FROM `tabProgram`
                                                        WHERE program_name='Exam Applicants'"""
                                           )

            if exists_program == ():
                program = frappe.get_doc({
                    "doctype": "Program",
                    "program_name": "Exam Applicants"
                }).insert(ignore_permissions=True)

            program = frappe.get_doc({
                "doctype":
                "Program Enrollment",
                "student":
                student.name,
                "academic_year":
                "2020",
                "program":
                "Exam Applicants",
                "enrollment_date":
                frappe.utils.get_datetime().date(),
                "docstatus":
                1
            }).insert(ignore_permissions=True)
        elif note == "Regular":

            exists_program = frappe.db.sql("""SELECT Count(*) FROM `tabProgram`
                                            WHERE program_name='Regular Applicants'"""
                                           )

            if exists_program == ():
                program = frappe.get_doc({
                    "doctype": "Program",
                    "program_name": "Regular Applicants"
                }).insert(ignore_permissions=True)

            program = frappe.get_doc({
                "doctype":
                "Program Enrollment",
                "student":
                student.name,
                "academic_year":
                "2020",
                "program":
                "Regular Applicants",
                "enrollment_date":
                frappe.utils.get_datetime().date(),
                "docstatus":
                1
            }).insert(ignore_permissions=True)
        else:
            if note:
                exists_program = frappe.db.sql(
                    """SELECT Count(*) FROM `tabProgram`
                                                WHERE program_name=%s""",
                    (note))

                if exists_program == ():
                    program = frappe.get_doc({
                        "doctype": "Program",
                        "program_name": note
                    }).insert(ignore_permissions=True)

                program = frappe.get_doc({
                    "doctype":
                    "Program Enrollment",
                    "student":
                    student.name,
                    "academic_year":
                    "2020",
                    "program":
                    note,
                    "enrollment_date":
                    frappe.utils.get_datetime().date(),
                    "docstatus":
                    1
                }).insert(ignore_permissions=True)

    else:
        user = frappe.get_doc("User", id_number + "@wela.online")
    return user.name