root/trunk/eCard/eCardMVC/adMoto.Payments.Web/Controllers/AccountController.cs @ 984

Wersja 984, 4.1 KB (wprowadzona przez alina, 16 years temu)

re #215 ujednolicenie nazw obiektow, modyfikacje dotyczace testow interfejsowych (dodanie tymczasowych rekowrdow do bazy na czas testowania )

RevLine 
[866]1using System;
2using System.Linq;
3using System.Web.Mvc;
4using System.Web.Security;
[970]5using adMoto.Payments.Core;
6using adMoto.Payments.Core.Data;
7using adMoto.Payments.Core.Interfaces;
[971]8using adMoto.Payments.Web.Models;
[866]9
[971]10namespace adMoto.Payments.Web.Controllers
[932]11{
[866]12    [HandleError]
13    public class AccountController : Controller
14    {
[970]15        private readonly IRepository<Invoice> _repository;
[971]16        private readonly PaymentsUtils _paymentsUtils;
[932]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();
[971]28            _paymentsUtils = new PaymentsUtils();
[866]29        }
30
[984]31        public AccountController(IFormsAuthentication formsAuth, IRepository<Invoice> repository, PaymentsUtils paymentsUtils)
[866]32        {
33            _repository = repository;
34            FormsAuth = formsAuth ?? new FormsAuthenticationService();
[984]35            _paymentsUtils = paymentsUtils;
[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
[971]43            _paymentsUtils.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        {
[971]52            _paymentsUtils.SetLanguage(language);
[984]53            var invoice = new Invoice();
54           
[932]55            if (!ValidateLogOn(nip, numerFaktury))
[984]56                return View();           
57           
58            invoice = _repository.FindInvoiceByNipNumber(nip, numerFaktury).SingleOrDefault();
59           
60            if (invoice == null)
[866]61                return View();
[984]62
[971]63            _paymentsUtils.SetUserLogger(nip, numerFaktury);
[866]64
65            FormsAuth.SignIn(nip, false);
[880]66
[866]67            if (!String.IsNullOrEmpty(returnUrl))
68                return Redirect(returnUrl);
[932]69           
[984]70            return RedirectToAction("Show", "Platnosc", new { id = invoice.ID_faktury });
[866]71        }
[932]72
[866]73        public ActionResult LogOff()
74        {
75            FormsAuth.SignOut();
76            return RedirectToAction("LogOn", "Account");
77        }
78
[932]79        private bool ValidateLogOn(string nip, string numerFaktury)
[866]80        {
[942]81            var errNip = HttpContext.GetGlobalResourceObject("tlumaczenia", "err_nip").ToString();
82            var errFaktura = HttpContext.GetGlobalResourceObject("tlumaczenia", "err_faktura").ToString();
83            var errTxt = HttpContext.GetGlobalResourceObject("tlumaczenia", "err_logowanie").ToString();
84   
[866]85            if (String.IsNullOrEmpty(nip))
[932]86                ModelState.AddModelError("nip", errNip);
[984]87           
[932]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    }
[971]100
[866]101    public interface IFormsAuthentication
102    {
103        void SignIn(string nip, bool createPersistentCookie);
104        void SignOut();
105    }
106
107    public class FormsAuthenticationService : IFormsAuthentication
108    {
109        public void SignIn(string nip, bool createPersistentCookie)
110        {
111            FormsAuthentication.SetAuthCookie(nip, createPersistentCookie);
112        }
113        public void SignOut()
114        {
115            FormsAuthentication.SignOut();
116        }
117    }
[932]118}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.