public HttpResponseMessage Register(UserRegister model)
        {
            HttpResponseMessage response;

            try
            {
                if (ModelState.IsValid)
                {
                    LoginHelpers User         = new LoginHelpers();
                    var          existingUser = User.RegisterHelpers(model);
                    if (existingUser.Count != 0)
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "User or Email already exist."));
                    }

                    //Create user and save to database
                    var    user = CreateUser(model);
                    object dbUser;

                    //Create token and save to database
                    var token = CreateToken(user[0], out dbUser);
                    User.SaveToken(user[0].User_Id, token);
                    response = Request.CreateResponse(new { dbUser, token });
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, new { success = false });
                }
            }
            catch (SqlException)
            {
                response = Request.CreateResponse(HttpStatusCode.InternalServerError);
            }
            return(response);
        }
Ejemplo n.º 2
0
        public async Task AttemptLogin_NonExistingUserIsEntered_ReturnsNull()
        {
            // Get the result from the attempted login
            var result = await LoginHelpers.AttemptLogin("0", "0".ToSecureString());

            // Check that the result is null
            Assert.IsNull(result);
        }
Ejemplo n.º 3
0
        public MainWindow()
        {
            InitializeComponent();
            if (Height > SystemParameters.VirtualScreenHeight || Width > SystemParameters.VirtualScreenWidth)
            {
                WindowState = WindowState.Maximized;
            }
            DevExpress.Utils.About.UAlgo.Default.DoEventObject(DevExpress.Utils.About.UAlgo.kDemo, DevExpress.Utils.About.UAlgo.pWPF, this);

            this.txt_UserName.Content = "欢迎您:" + LoginHelpers.GetSettingString("nickName");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 更换用户信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_exit_Click(object sender, RoutedEventArgs e)
        {
            LoginHelpers.UpdateSettingString("userName", "");
            LoginHelpers.UpdateSettingString("nickName", "");
            LoginHelpers.UpdateSettingString("password", "");
            LoginHelpers.UpdateSettingString("isRemember", "");

            LoginPage loginPage = new LoginPage();

            loginPage.Show();
            this.Close();
        }
Ejemplo n.º 5
0
        private void btn_login_Click(object sender, RoutedEventArgs e)
        {
            //判断用户名不能为空
            if (string.IsNullOrEmpty(txtUsername.Text))
            {
                MessageBox.Show("用户名不能为空!");
                return;
            }
            //判断密码不能为空
            if (string.IsNullOrEmpty(txtPassword.Password))
            {
                MessageBox.Show("密码不能为空!");
                return;
            }
            beginImport();//进度条显示

            UserInfo info = new UserInfo();

            info.UserName = txtUsername.Text;                     //用户名
            info.Password = txtPassword.Password;                 //密码
            bool IsSaveLoginInfo = ckbRemember.IsChecked == true; //是否保存登陆账号密码
            //验证用户名和密码
            bool result = new LoginService().doLogin(info);

            if (result)
            {
                LoginHelpers.UpdateSettingString("nickName", info.NickName);
                //判断是否记住用户信息
                if (Convert.ToBoolean(ckbRemember.IsChecked))
                {
                    LoginHelpers.UpdateSettingString("userName", info.UserName);
                    LoginHelpers.UpdateSettingString("password", info.Password);
                    LoginHelpers.UpdateSettingString("isRemember", "true");
                }
                else
                {
                    LoginHelpers.UpdateSettingString("userName", "");
                    LoginHelpers.UpdateSettingString("password", "");
                    LoginHelpers.UpdateSettingString("isRemember", "");
                }
                MainWindow mainWindow = new MainWindow();
                mainWindow.Show();
                this.Close();
            }
            else
            {
                MessageBox.Show("用户名或密码错误,请重新输入!");
                pb_import.Visibility = Visibility.Hidden;
                return;
            }
        }
        public HttpResponseMessage Login(UserLogin model)
        {
            HttpResponseMessage response = null;

            if (ModelState.IsValid)
            {
                try
                {
                    LoginHelpers User         = new LoginHelpers();
                    var          existingUser = User.CheckUser(model);
                    if (existingUser.Count == 0)
                    {
                        response = Request.CreateResponse(HttpStatusCode.NotFound, "User Doesn't exist.");
                    }
                    else
                    {
                        if ((!String.IsNullOrWhiteSpace(model.UserName)) && (!String.IsNullOrWhiteSpace(model.Password)))
                        {
                            var loginSuccess =
                                string.Equals(EncryptPassword(model.Password, existingUser[0].Salt),
                                              existingUser[0].Password);

                            if (loginSuccess)
                            {
                                response = Request.CreateResponse(new { existingUser[0].User_Id, existingUser[0].UserName, existingUser[0].Token });
                            }
                            else
                            {
                                response = Request.CreateResponse(HttpStatusCode.Forbidden, "Please Provide correct User Credentials");
                            }
                        }
                        else
                        {
                            response = Request.CreateResponse(HttpStatusCode.Forbidden, "Password or Username not provided");
                        }
                    }
                }
                catch (SqlException)
                {
                    response = Request.CreateResponse(HttpStatusCode.InternalServerError);
                }
            }
            else
            {
                response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Bad Request");
            }
            return(response);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 判断是否自动登录
        /// </summary>
        public void AutoLogin()
        {
            txtUsername.Text     = LoginHelpers.GetSettingString("userName");
            txtPassword.Password = LoginHelpers.GetSettingString("password");

            if (!string.IsNullOrEmpty(txtUsername.Text) && LoginHelpers.GetSettingString("isRemember") == "true")
            {
                ckbRemember.IsChecked = true;

                MainWindow mainWindow = new MainWindow();
                mainWindow.Show();
                this.Close();
            }
            else
            {
                ckbRemember.IsChecked = false;
            }
        }
        /// Create a new user and saves it to the database
        private IList <User> CreateUser(UserRegister NewUser)
        {
            LoginHelpers Newuser      = new LoginHelpers();
            var          passwordSalt = CreateSalt();
            var          user         = new User
            {
                Email    = NewUser.Email,
                Password = EncryptPassword(NewUser.Password, passwordSalt),
                UserName = NewUser.UserName,
                Age      = NewUser.Age,
                Gender   = NewUser.Gender,
                Salt     = passwordSalt,
                Token    = ""
            };

            Newuser.SaveNewUser(user);
            var newUSer = Newuser.ReturnNewUSer(user.UserName);

            return(newUSer);
        }