Kopírujeme emaily z osoby do usera, aby jednoduše fungovalo resetování hesla.
This commit is contained in:
		
							parent
							
								
									65a76935a6
								
							
						
					
					
						commit
						83aa9a1758
					
				
					 3 changed files with 37 additions and 0 deletions
				
			
		
							
								
								
									
										22
									
								
								seminar/migrations/0073_copy_osoba_email_to_user_email.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								seminar/migrations/0073_copy_osoba_email_to_user_email.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,22 @@ | |||
| # Generated by Django 2.2.9 on 2020-01-15 21:28 | ||||
| 
 | ||||
| from django.db import migrations | ||||
| 
 | ||||
| def copy_mails(apps, schema_editor): | ||||
| 	Osoba = apps.get_model('seminar', 'Osoba') | ||||
| 
 | ||||
| 	for o in Osoba.objects.all(): | ||||
| 		if o.user is not None: | ||||
| 			u = o.user | ||||
| 			u.email = o.email | ||||
| 			u.save() | ||||
| 
 | ||||
| class Migration(migrations.Migration): | ||||
| 
 | ||||
|     dependencies = [ | ||||
|         ('seminar', '0072_auto_20191204_2257'), | ||||
|     ] | ||||
| 
 | ||||
|     operations = [ | ||||
|         migrations.RunPython(copy_mails, migrations.RunPython.noop) | ||||
|     ] | ||||
|  | @ -130,6 +130,17 @@ class Osoba(SeminarModelBase): | |||
| 	def __str__(self): | ||||
| 		return self.plne_jmeno() | ||||
| 
 | ||||
| 	# Overridujeme save Osoby, aby když si změní e-mail, aby se projevil i v | ||||
| 	# Userovi (a tak se dal poslat mail s resetem hesla) | ||||
| 	def save(self, *args, **kwargs): | ||||
| 		if self.user is not None: | ||||
| 			u = self.user | ||||
| 			# U svatého tučňáka, prosím ať tohle funguje. | ||||
| 			# (Takhle se kódit asi nemá...) | ||||
| 			u.email = self.email | ||||
| 			u.save() | ||||
| 		super().save() | ||||
| 
 | ||||
| # | ||||
| # Mělo by být částečně vytaženo z Aesopa | ||||
| # viz https://ovvp.mff.cuni.cz/wiki/aesop/export-skol. | ||||
|  |  | |||
|  | @ -1296,6 +1296,7 @@ class LogoutView(auth_views.LogoutView): | |||
| 	# Pavel: Vůbec nevím, proč to s _lazy funguje, ale bez toho to bylo rozbité. | ||||
| 	next_page = reverse_lazy('titulni_strana') | ||||
| 
 | ||||
| # "Chci resetovat heslo" | ||||
| class PasswordResetView(auth_views.PasswordResetView): | ||||
| 	#template_name = 'seminar/password_reset.html' | ||||
| 	# TODO: vlastní email_template_name a subject_template_name a html_email_template_name | ||||
|  | @ -1303,14 +1304,17 @@ class PasswordResetView(auth_views.PasswordResetView): | |||
| 	from_email = 'login@mam.mff.cuni.cz' | ||||
| 	# TODO: přepsat User-a :-( | ||||
| 
 | ||||
| # "Poslali jsme e-mail (pokud bylo kam))" | ||||
| class PasswordResetDoneView(auth_views.PasswordResetDoneView): | ||||
| 	#template_name = 'seminar/password_reset_done.html' | ||||
| 	pass | ||||
| 
 | ||||
| # "Vymysli si heslo" | ||||
| class PasswordResetConfirmView(auth_views.PasswordResetConfirmView): | ||||
| 	#template_name = 'seminar/password_confirm_done.html' | ||||
| 	success_url = reverse_lazy('reset_password_complete') | ||||
| 
 | ||||
| # "Heslo se asi změnilo." | ||||
| class PasswordResetCompleteView(auth_views.PasswordResetCompleteView): | ||||
| 	#template_name = 'seminar/password_complete_done.html' | ||||
| 	pass | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Pavel 'LEdoian' Turinsky
						Pavel 'LEdoian' Turinsky