Coverage for /home/runner/work/viur-core/viur-core/viur/src/viur/core/render/html/user.py: 0%

67 statements  

« prev     ^ index     » next       coverage.py v7.6.3, created at 2024-10-16 22:16 +0000

1import typing as t 

2 

3from . import default as DefaultRender 

4from viur.core.modules.user import UserSecondFactorAuthentication 

5 

6class Render(DefaultRender): # Render user-data to xml 

7 loginTemplate = "user_login" 

8 loginChoicesTemplate = "user_login_choices" 

9 logoutSuccessTemplate = "user_logout_success" 

10 loginSuccessTemplate = "user_login_success" 

11 verifySuccessTemplate = "user_verify_success" 

12 verifyFailedTemplate = "user_verify_failed" 

13 passwdRecoverInfoTemplate = "user_passwdrecover_info" 

14 second_factor_add_template = "user_secondfactor_add" 

15 second_factor_add_success_template = "user_secondfactor_add_success" 

16 second_factor_choice_template = "user_second_factor_choice" 

17 

18 def _choose_template(self, tpl: None | str, fallback_attribute: str) -> str: 

19 if tpl: 

20 return tpl 

21 if hasattr(self.parent, fallback_attribute): 

22 return getattr(self.parent, fallback_attribute) 

23 return getattr(self, fallback_attribute) 

24 

25 def login_disabled(self, authMethods, tpl: str | None = None, **kwargs): 

26 tpl = self._choose_template(tpl, "loginTemplate") 

27 template = self.getEnv().get_template(self.getTemplateFileName(tpl)) 

28 return template.render(authMethods=authMethods, **kwargs) 

29 

30 def login(self, skel, tpl: str | None = None, **kwargs): 

31 tpl = self._choose_template(tpl, "loginTemplate") 

32 return self.add(skel, tpl=tpl, loginFailed=kwargs.get("loginFailed", False), 

33 accountStatus=kwargs.get("accountStatus")) 

34 

35 def loginChoices(self, authMethods, tpl: str | None = None, **kwargs): 

36 tpl = self._choose_template(tpl, "loginChoicesTemplate") 

37 template = self.getEnv().get_template(self.getTemplateFileName(tpl)) 

38 return template.render(authMethods=authMethods, **kwargs) 

39 

40 def loginSucceeded(self, tpl: str | None = None, **kwargs): 

41 tpl = self._choose_template(tpl, "loginSuccessTemplate") 

42 template = self.getEnv().get_template(self.getTemplateFileName(tpl)) 

43 return template.render(**kwargs) 

44 

45 def logoutSuccess(self, tpl: str | None = None, **kwargs): 

46 tpl = self._choose_template(tpl, "logoutSuccessTemplate") 

47 template = self.getEnv().get_template(self.getTemplateFileName(tpl)) 

48 return template.render(**kwargs) 

49 

50 def verifySuccess(self, skel, tpl: str | None = None, **kwargs): 

51 tpl = self._choose_template(tpl, "verifySuccessTemplate") 

52 template = self.getEnv().get_template(self.getTemplateFileName(tpl)) 

53 return template.render(**kwargs) 

54 

55 def verifyFailed(self, tpl: str | None = None, **kwargs): 

56 tpl = self._choose_template(tpl, "verifyFailedTemplate") 

57 template = self.getEnv().get_template(self.getTemplateFileName(tpl)) 

58 return template.render(**kwargs) 

59 

60 def passwdRecoverInfo(self, msg, skel=None, tpl: str | None = None, **kwargs): 

61 tpl = self._choose_template(tpl, "passwdRecoverInfoTemplate") 

62 template = self.getEnv().get_template(self.getTemplateFileName(tpl)) 

63 if skel: 

64 skel.renderPreparation = self.renderBoneValue 

65 return template.render(skel=skel, msg=msg, **kwargs) 

66 

67 def passwdRecover(self, *args, **kwargs): 

68 return self.edit(*args, **kwargs) 

69 

70 def second_factor_add(self, action_name: str, name: str, add_url: str, 

71 tpl: str | None, otp_uri=None): 

72 tpl = self._choose_template(tpl, "second_factor_add_template") 

73 template = self.getEnv().get_template(self.getTemplateFileName(tpl)) 

74 return template.render(action_name=action_name, name=name, add_url=add_url, otp_uri=otp_uri) 

75 

76 def second_factor_add_success(self, action_name: str, name: str, tpl: str | None = None): 

77 tpl = self._choose_template(tpl, "second_factor_add_success_template") 

78 template = self.getEnv().get_template(self.getTemplateFileName(tpl)) 

79 return template.render(action_name=action_name, name=name) 

80 

81 def second_factor_choice(self, 

82 second_factors: t.Iterable[UserSecondFactorAuthentication], 

83 tpl: str | None = None): 

84 tpl = self._choose_template(tpl, "second_factor_choice_template") 

85 template = self.getEnv().get_template(self.getTemplateFileName(tpl)) 

86 return template.render(second_factors=second_factors)