// To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (UserInfo.Password == null)
            {
                return(null);
            }

            Image tempImage = Image.FromFile("Images/DefaultImage.jpg");
            var   ms        = new MemoryStream();

            tempImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            UserInfo.UserImage       = ms.ToArray();
            UserInfo.ImagePath       = "~/Images/DefaultImage.jpg";
            UserInfo.Twitter         = "https://twitter.com";
            UserInfo.Linkedin        = "https://www.linkedin.com/";
            UserInfo.Facebook        = "https://www.facebook.com/";
            UserInfo.CreditHours     = 0;
            UserInfo.Biography       = "Temporary";
            UserInfo.AccountCharges  = 0;
            UserInfo.AccountPayments = 0;



            if (!ModelState.IsValid)
            {
                return(Page());
            }



            // hash password
            UserInfo.Password = Hash.Create(PasswordEncryption.EncryptString(UserInfo.Password));


            var Users = from x in _context.UserInfo select x;

            Users = Users.Where(s => s.Email.Equals(UserInfo.Email));


            if (Users.Count() == 0)
            {
                _context.UserInfo.Add(UserInfo);
                await _context.SaveChangesAsync();

                return(RedirectToPage("../SignIn/signin"));
            }
            else
            {
                return(null);
            }
        }
        public async Task <IActionResult> OnPostAsync()
        {
            var Users  = from m in _context.UserInfo select m;
            int UserID = (int)HttpContext.Session.GetInt32("UserID");

            Users = Users.Where(x => x.ID.Equals(UserID));


            if (await TryUpdateModelAsync <UserInfo>(UserInfo, "userinfo", s => s.FirstName, s => s.LastName, s => s.Email,
                                                     s => s.Birthdate, s => s.Password, s => s.Biography, s => s.Twitter, s => s.Linkedin, s => s.Facebook, s => s.IsInstructor))
            {
                if (UserInfo.Password == null)
                {
                    UserInfo.Password = (from m in Users select m.Password).Single();
                }
                else
                {
                    UserInfo.Password = Hash.Create(PasswordEncryption.EncryptString(UserInfo.Password));
                }

                UserInfo.Birthdate = (from m in Users select m.Birthdate).Single();

                if (UserInfo.ImagePath == null)
                {
                    UserInfo.UserImage = (from m in Users select m.UserImage).Single();
                    UserInfo.ImagePath = (from m in Users select m.ImagePath).Single();
                }
                if (this.FormImage != null)
                {
                    using var memoryStream = new MemoryStream();
                    await FormImage.CopyToAsync(memoryStream);

                    Image        img = Image.FromStream(memoryStream);
                    MemoryStream ms  = new MemoryStream();
                    img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
                    UserInfo.UserImage = memoryStream.ToArray();
                    UserInfo.ImagePath = null;
                }

                if (UserInfo.Biography == null)
                {
                    UserInfo.Biography = (from m in Users select m.Biography).Single();
                }
                _context.UserInfo.Update(UserInfo);
                await _context.SaveChangesAsync();

                return(RedirectToPage("../Profile/Profile"));
            }

            return(Page());
        }
Beispiel #3
0
        public async Task <RedirectToPageResult> OnGetAsync()
        {
            HttpContext.Session.Clear();
            var Users = from m in _context.UserInfo select m;

            if (!string.IsNullOrEmpty(UserEmail) && !string.IsNullOrEmpty(UserPassword))
            {
                HttpContext.Session.SetString("Password", UserPassword);
                // hash password
                UserPassword = Hash.Create(PasswordEncryption.EncryptString(UserPassword));


                UserEmail = UserEmail.ToLower();
                Users     = Users.Where(s => s.Email.Equals(UserEmail));
                Users     = Users.Where(t => t.Password.Equals(UserPassword));



                if (Users.Count() == 0)
                {
                    //Need code to display error message
                }
                else if (Users.Count() == 1)
                {
                    HttpContext.Session.SetString("FirstName", (from m in Users select m.FirstName).Single());
                    HttpContext.Session.SetString("LastName", (from m in Users select m.LastName).Single());
                    HttpContext.Session.SetInt32("UserID", (from m in Users select m.ID).Single());
                    if ((from m in Users select m.IsInstructor).Single() == true)
                    {
                        HttpContext.Session.SetInt32("IsInstructor", 1);
                    }
                    else
                    {
                        HttpContext.Session.SetInt32("IsInstructor", 0);
                    }
                    return(RedirectToPage("../MainPage/MainPage"));


                    //          UserInfo = await Users.ToListAsync();
                }
            }
            UserInfo = await Users.ToListAsync();

            return(null);

            //            UserInfo = await _context.UserInfo.ToListAsync();
        }