root/trunk/eCard/eCardMVC/Platnosci/Controllers/AccountController.cs @ 880

Wersja 880, 4.4 KB (wprowadzona przez alina, 16 years temu)

re #215 modyfikacja akcji Potwierdzenie(do wyswietlenia statusu), dodanie funkcji InitErrorViewData?, zapisywanie plikow z bledami w katalogu Log...

Line 
1using System;
2using System.Linq;
3using System.Text;
4using System.Web.Mvc;
5using System.Web.Security;
6using System.Collections.Generic;
7using Platnosci.Core.Linq;
8using Platnosci.Models;
9using System.Globalization;
10using System.Threading;
11using Platnosci.Core.Interface;
12using System.Resources;
13using Platnosci.Core;
14
15namespace Platnosci.Controllers
16
17
18    [HandleError]
19    public class AccountController : Controller
20    {
21
22        private readonly IRepository<vPlatnosciEcard> _repository;
23        private readonly PlatnosciDataContext _context;
24        private FunkcjePlatnosci _func;
25               
26        public IFormsAuthentication FormsAuth
27        {
28            get;
29            private set;
30        }
31
32        public AccountController()
33        {
34            _repository = new Repository<vPlatnosciEcard>(new DataContext1());
35            FormsAuth = new FormsAuthenticationService();
36            _context = new PlatnosciDataContext();
37            _func = new FunkcjePlatnosci();
38        }
39
40        public AccountController(IFormsAuthentication formsAuth, IRepository<vPlatnosciEcard> repository, PlatnosciDataContext context, FunkcjePlatnosci func)
41        {
42            _repository = repository;
43            FormsAuth = formsAuth ?? new FormsAuthenticationService();
44            _context = context;
45            _func = func;
46        }
47
48        public ActionResult LogOn(string language)
49        {
50            language = _func.setLanguage(language);
51            return View();
52        }
53
54        [AcceptVerbs(HttpVerbs.Post)]
55        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
56            Justification = "Needs to take same parameter type as Controller.Redirect()")]
57        public ActionResult LogOn(string nip, string numer_faktury, string returnUrl, string language)
58        {
59
60            language = _func.setLanguage(language);
61            vPlatnosciEcard platnosc = new vPlatnosciEcard();   
62            if (!ValidateLogOn(nip, numer_faktury))
63            {
64                return View();
65            }
66            else
67            {
68                var Login = _repository.FindInvoiceByNipNumber(nip, numer_faktury).SingleOrDefault();
69                platnosc = Login;
70                if (platnosc == null) return View();
71            }
72            _func.SetUserLogger(nip, numer_faktury);
73
74            FormsAuth.SignIn(nip, false);
75
76            if (!String.IsNullOrEmpty(returnUrl))
77            {
78                return Redirect(returnUrl);
79            }
80            else return RedirectToAction("Show", "Platnosc", new { id = platnosc.ID_faktury });         
81        }
82        public ActionResult LogOff()
83        {
84            FormsAuth.SignOut();
85            return RedirectToAction("LogOn", "Account");
86        }
87
88        private bool ValidateLogOn(string nip, string numer_faktury)
89        {
90            if (String.IsNullOrEmpty(nip))
91            {
92                string err_nip = HttpContext.GetGlobalResourceObject("tlumaczenia", "err_nip").ToString();
93                ModelState.AddModelError("nip", err_nip);
94            }
95            if (String.IsNullOrEmpty(numer_faktury))
96            {
97                string err_faktura = HttpContext.GetGlobalResourceObject("tlumaczenia", "err_faktura").ToString();
98                ModelState.AddModelError("numer_faktury", err_faktura);
99            }
100            if (ModelState.IsValid)
101            {
102                bool DaneOk = _repository.Exists(u => u.Faktura_Numer == numer_faktury && u.nip == nip);
103                if (DaneOk == false)
104                {
105                    string err_logowanie = HttpContext.GetGlobalResourceObject("tlumaczenia", "err_logowanie").ToString();
106                    ModelState.AddModelError("_FORM", err_logowanie);
107                }               
108            }
109            return ModelState.IsValid;
110        }
111    }
112    public interface IFormsAuthentication
113    {
114        void SignIn(string nip, bool createPersistentCookie);
115        void SignOut();
116    }
117
118    public class FormsAuthenticationService : IFormsAuthentication
119    {
120        public void SignIn(string nip, bool createPersistentCookie)
121        {
122            FormsAuthentication.SetAuthCookie(nip, createPersistentCookie);
123        }
124        public void SignOut()
125        {
126            FormsAuthentication.SignOut();
127        }
128    }
129}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.