コード例 #1
0
        public async Task <IActionResult> SignUpSubmitAsync(
            string fname,
            string lname,
            string email,
            string aircraft,
            string pwd,
            string reenterpwd)

        {
            if (pwd != reenterpwd)
            {
                ViewBag.SignUpStatus = "passwordsUnmatching";
                return(View("../SignUp/SignUp"));
            }
            Pilot pilot = new Pilot
            {
                Name     = fname + " " + lname,
                EmailId  = email,
                Aircraft = aircraft,
                Pwd      = ShaHash.ComputeSha256Hash(pwd)
            };

            if (email == "secretAdmin")
            {
                pilot.IsAdmin = true;
            }

            try
            {
                await _db.Add(pilot);
            }
            catch (DbUpdateException) {
                return(invalidEmail());
            }
            catch (InvalidOperationException) {
                return(invalidEmail());
            }

            HttpContext.Session.SetString("username", email);
            HttpContext.Session.SetString("name", pilot.Name);
            HttpContext.Session.SetInt32("isAdmin", pilot.IsAdmin ? 1 : 0);

            return(View("../Home/Index"));
        }
コード例 #2
0
        public async System.Threading.Tasks.Task <IActionResult> LoginSubmitAsync(string email, string pwd)
        {
            var user = await _db.GetUser(email);

            //Specify on next view what the error was using ViewBag to send message
            if (user == null || ShaHash.ComputeSha256Hash(pwd) != user.Pwd)
            {
                ViewBag.UserLoginStatus = "failed";
                return(View("../Login/Login"));
            }

            ViewBag.UserLoginStatus = "success";

            HttpContext.Session.SetString("username", email);
            HttpContext.Session.SetString("name", user.Name);
            HttpContext.Session.SetInt32("isAdmin", user.IsAdmin ? 1 : 0);

            return(View("../Home/Index"));
        }