| [866] | 1 | using System;
|
|---|
| 2 | using System.Linq;
|
|---|
| 3 | using System.Web.Mvc;
|
|---|
| 4 | using System.Web.Security;
|
|---|
| [970] | 5 | using adMoto.Payments.Core;
|
|---|
| 6 | using adMoto.Payments.Core.Data;
|
|---|
| 7 | using adMoto.Payments.Core.Interfaces;
|
|---|
| [866] | 8 | using Platnosci.Models;
|
|---|
| 9 |
|
|---|
| 10 | namespace Platnosci.Controllers
|
|---|
| [932] | 11 | {
|
|---|
| [866] | 12 | [HandleError]
|
|---|
| 13 | public class AccountController : Controller
|
|---|
| 14 | {
|
|---|
| [970] | 15 | private readonly IRepository<Invoice> _repository;
|
|---|
| [932] | 16 | private readonly FunkcjePlatnosci _funkcjePlatnosci;
|
|---|
| 17 |
|
|---|
| [866] | 18 | public IFormsAuthentication FormsAuth
|
|---|
| 19 | {
|
|---|
| 20 | get;
|
|---|
| 21 | private set;
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | public AccountController()
|
|---|
| 25 | {
|
|---|
| [970] | 26 | _repository = new Repository<Invoice>(new DataContext());
|
|---|
| [866] | 27 | FormsAuth = new FormsAuthenticationService();
|
|---|
| [932] | 28 | _funkcjePlatnosci = new FunkcjePlatnosci();
|
|---|
| [866] | 29 | }
|
|---|
| 30 |
|
|---|
| [970] | 31 | public AccountController(IFormsAuthentication formsAuth, IRepository<Invoice> repository, FunkcjePlatnosci func)
|
|---|
| [866] | 32 | {
|
|---|
| 33 | _repository = repository;
|
|---|
| 34 | FormsAuth = formsAuth ?? new FormsAuthenticationService();
|
|---|
| [932] | 35 | _funkcjePlatnosci = func;
|
|---|
| [866] | 36 | }
|
|---|
| 37 |
|
|---|
| 38 | public ActionResult LogOn(string language)
|
|---|
| 39 | {
|
|---|
| [948] | 40 | if (language != "pl" && language != "en" && language != "de")
|
|---|
| 41 | return RedirectToAction("LogOn", "Account", new { language = "pl" });
|
|---|
| 42 |
|
|---|
| [950] | 43 | _funkcjePlatnosci.SetLanguage(language);
|
|---|
| [866] | 44 | return View();
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | [AcceptVerbs(HttpVerbs.Post)]
|
|---|
| 48 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
|
|---|
| 49 | Justification = "Needs to take same parameter type as Controller.Redirect()")]
|
|---|
| [932] | 50 | public ActionResult LogOn(string nip, string numerFaktury, string returnUrl, string language)
|
|---|
| [866] | 51 | {
|
|---|
| [950] | 52 | _funkcjePlatnosci.SetLanguage(language);
|
|---|
| [970] | 53 | var platnosc = new Invoice();
|
|---|
| [932] | 54 | if (!ValidateLogOn(nip, numerFaktury))
|
|---|
| [866] | 55 | {
|
|---|
| 56 | return View();
|
|---|
| 57 | }
|
|---|
| [932] | 58 |
|
|---|
| 59 | var login = _repository.FindInvoiceByNipNumber(nip, numerFaktury).SingleOrDefault();
|
|---|
| 60 | platnosc = login;
|
|---|
| 61 | if (platnosc == null) return View();
|
|---|
| 62 | _funkcjePlatnosci.SetUserLogger(nip, numerFaktury);
|
|---|
| [866] | 63 |
|
|---|
| 64 | FormsAuth.SignIn(nip, false);
|
|---|
| [880] | 65 |
|
|---|
| [866] | 66 | if (!String.IsNullOrEmpty(returnUrl))
|
|---|
| 67 | {
|
|---|
| 68 | return Redirect(returnUrl);
|
|---|
| 69 | }
|
|---|
| [932] | 70 |
|
|---|
| 71 | return RedirectToAction("Show", "Platnosc", new { id = platnosc.ID_faktury });
|
|---|
| [866] | 72 | }
|
|---|
| [932] | 73 |
|
|---|
| [866] | 74 | public ActionResult LogOff()
|
|---|
| 75 | {
|
|---|
| 76 | FormsAuth.SignOut();
|
|---|
| 77 | return RedirectToAction("LogOn", "Account");
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| [932] | 80 | private bool ValidateLogOn(string nip, string numerFaktury)
|
|---|
| [866] | 81 | {
|
|---|
| [942] | 82 | var errNip = HttpContext.GetGlobalResourceObject("tlumaczenia", "err_nip").ToString();
|
|---|
| 83 | var errFaktura = HttpContext.GetGlobalResourceObject("tlumaczenia", "err_faktura").ToString();
|
|---|
| 84 | var errTxt = HttpContext.GetGlobalResourceObject("tlumaczenia", "err_logowanie").ToString();
|
|---|
| 85 |
|
|---|
| [866] | 86 | if (String.IsNullOrEmpty(nip))
|
|---|
| [932] | 87 | ModelState.AddModelError("nip", errNip);
|
|---|
| 88 | if (String.IsNullOrEmpty(numerFaktury))
|
|---|
| 89 | ModelState.AddModelError("numerFaktury", errFaktura);
|
|---|
| [942] | 90 |
|
|---|
| [866] | 91 | if (ModelState.IsValid)
|
|---|
| 92 | {
|
|---|
| [932] | 93 | var daneOk = _repository.Exists(u => u.Faktura_Numer == numerFaktury && u.nip == nip);
|
|---|
| 94 | if (daneOk == false)
|
|---|
| [942] | 95 | ModelState.AddModelError("_FORM", errTxt);
|
|---|
| [866] | 96 | }
|
|---|
| 97 | return ModelState.IsValid;
|
|---|
| 98 | }
|
|---|
| 99 | }
|
|---|
| 100 | public interface IFormsAuthentication
|
|---|
| 101 | {
|
|---|
| 102 | void SignIn(string nip, bool createPersistentCookie);
|
|---|
| 103 | void SignOut();
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | public class FormsAuthenticationService : IFormsAuthentication
|
|---|
| 107 | {
|
|---|
| 108 | public void SignIn(string nip, bool createPersistentCookie)
|
|---|
| 109 | {
|
|---|
| 110 | FormsAuthentication.SetAuthCookie(nip, createPersistentCookie);
|
|---|
| 111 | }
|
|---|
| 112 | public void SignOut()
|
|---|
| 113 | {
|
|---|
| 114 | FormsAuthentication.SignOut();
|
|---|
| 115 | }
|
|---|
| 116 | }
|
|---|
| [932] | 117 | } |
|---|