Пример #1
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (email.Text != "" && password.Password != "")
     {
         if (checkEmaillogin(email.Text))
         {
             Staff loginStaff = getEmailLogin(email.Text);
             if (loginStaff != null)
             {
                 if (loginStaff.password == password.Password)
                 {
                     error.Text       = "Login success";
                     error.Foreground = Brushes.Green;
                     CurrentStaff.setCurrentStaff(loginStaff);
                     loginSuccess();
                 }
                 else
                 {
                     error.Text = "Wrong password";
                 }
             }
             else
             {
                 error.Text = "Email not exist";
             }
         }
         else
         {
             Staff loginStaff = getIDLogin(email.Text);
             if (loginStaff != null)
             {
                 if (loginStaff.password == password.Password)
                 {
                     error.Text       = "Login success";
                     error.Foreground = Brushes.Green;
                     CurrentStaff.setCurrentStaff(loginStaff);
                     loginSuccess();
                 }
                 else
                 {
                     error.Text = "Wrong password";
                 }
             }
             else
             {
                 error.Text = "ID not exist";
             }
         }
     }
     else
     {
         error.Text = "Email or Password is empty";
     }
 }
Пример #2
0
        public async Task <ActionResult> UserRegistration(UserViewModel userViewModel, string ButtonType)
        {
            if (ButtonType == "Next")
            {
                if (ModelState.IsValid)
                {
                    CurrentUserModel = userViewModel;
                    ApplicationDbContext context = new ApplicationDbContext();

                    var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));

                    var user = new ApplicationUser {
                        UserName = CurrentUserModel.Username, Email = CurrentUserModel.Email, DisplayName = CurrentStaff.GetFullName()
                    };
                    var result = await UserManager.CreateAsync(user, CurrentUserModel.Password);

                    if (result.Succeeded)
                    {
                        if (CurrentStaff.StaffType == BLL.Constants.StaffTypes.TEACHER)
                        {
                            UserManager.AddToRole(user.Id, "Teacher");
                            var teacher = new Teacher()
                            {
                                ID = CurrentStaff.ID
                            };
                            _unitOfWork.Teachers.Add(teacher);
                        }


                        CurrentStaff.user_id = user.Id;

                        _service.Update(CurrentStaff);
                        _unitOfWork.Addresss.Update(CurrentStaff.Address); // just to make sure



                        try
                        {
                            ApplicationSignInManager SignInManager = HttpContext.GetOwinContext().Get <ApplicationSignInManager>();
                            await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                            await _unitOfWork.SaveAsync();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                        }


                        ModelState.Clear();

                        return(View("SuccessRegistration", CurrentStaff));
                    }
                }
            }


            else if (ButtonType == "Back")
            {
                return(View("StaffInfo", CurrentStaff));
            }



            return(View());
        }