示例#1
0
文件: Student.cs 项目: liguifa/Mooc
 public LoginInModel <StudentClient.Models.Student> Login(string username, string password)
 {
     try
     {
         LoginInModel <StudentClient.Models.Student> loginIn = new LoginInModel <StudentClient.Models.Student>();
         if (base.SearchCount(d => !d.Student_IsDel && d.Student_Email.Equals(username)) > 0)
         {
             List <StudentClient.Models.Student> students = base.Search(d => !d.Student_IsDel && d.Student_Email.Equals(username));
             if (students.Count > 0)
             {
                 StudentClient.Models.Student student = students.First();
                 if (student.Student_Password.Equals(Md5.GetEncryptionValue(password)))
                 {
                     loginIn.IsLogin     = true;
                     loginIn.CurrentUser = student;
                     return(loginIn);
                 }
             }
         }
         loginIn.IsLogin = false;
         return(loginIn);
     }
     catch (Exception e)
     {
         mLog.Error("An error has occurred in the login,error:{0}", e.ToString());
         throw;
     }
 }
示例#2
0
 public MResultModel AdminLogin(LoginInModel model)
 {
     try
     {
         if (VerificationImageCode(model.ValidateCode))
         {
             LoginOutModel resM = _bll.Login(model.UserName, model.Password);
             if (resM != null)
             {
                 return(MResultModel <LoginOutModel> .GetSuccessResultM(resM, "登录成功"));
             }
             else
             {
                 return(MResultModel.GetFailResultM("登录失败,用户名或者密码错误"));
             }
         }
         else
         {
             return(MResultModel.GetFailResultM("登录失败,验证码错误"));
         }
     }
     catch (ApplicationException ex)
     {
         return(MResultModel.GetFailResultM(ex.Message));
     }
 }
示例#3
0
        public UserModel Login(LoginInModel lim)
        {
            var user = new User();

            try
            {
                user = userio.LoadEntity(u => u.Username == lim.UserName).FirstOrDefault();
            }
            catch (Exception e)
            {
                var de = new DataException();
                de.Info = ErrorType.IOError.GetHashCode().ToString();
                throw de;
            }
            if (user == null)
            {
                var de = new DataException();
                de.Info = ErrorType.UsernotExist.GetHashCode().ToString();
                throw de;
            }
            if (lim.Password == user.Password)
            {
                var um = new UserModel();
                um.Id       = user.Id;
                um.Name     = user.Name;
                um.UserName = user.Username;
                return(um);
            }
            else
            {
                var de = new DataException();
                de.Info = ErrorType.WrongPassword.GetHashCode().ToString();
                throw de;
            }
        }
示例#4
0
        public HttpResponseMessage Login(LoginInModel lim)
        {
            StringContent   stringContent;
            ProjectResponse response = new ProjectResponse();
            var             result   = new UserModel();
            var             sps      = new SignUpService();

            try
            {
                result = sps.Login(lim);
            }
            catch (DataException de)
            {
                response.internalcode = de.Info;
                if (de.Info == "21")
                {
                    response.status = "IOerror";
                    stringContent   = new StringContent(JsonConvert.SerializeObject(response), Encoding.UTF8, "application/json");
                }
                else if (de.Info == "3")
                {
                    response.status = "Passworderror";
                    stringContent   = new StringContent(JsonConvert.SerializeObject(response), Encoding.UTF8, "application/json");
                }
                else if (de.Info == "2")
                {
                    response.status = "UserNotexist";
                    stringContent   = new StringContent(JsonConvert.SerializeObject(response), Encoding.UTF8, "application/json");
                }
                else
                {
                    response.status = "Unknownerror";
                    stringContent   = new StringContent(JsonConvert.SerializeObject(response), Encoding.UTF8, "application/json");
                }
                HttpResponseMessage hrm = new HttpResponseMessage();
                hrm.Content = stringContent;
                return(hrm);
            }

            var resp = new HttpResponseMessage();

            var nv = new NameValueCollection();

            nv["user"]     = result.Name;
            nv["username"] = result.UserName;
            nv["id"]       = result.Id;
            var cookie = new CookieHeaderValue("session", nv);

            response.internalcode = "1";
            response.status       = "success";
            resp.Content          = new StringContent(JsonConvert.SerializeObject(response), Encoding.UTF8, "application/json");
            resp.Headers.AddCookies(new CookieHeaderValue[] { cookie });



            return(resp);
        }
        public async Task <IActionResult> Login(LoginInModel loginData)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var result = await _signInManager.PasswordSignInAsync(loginData.Username, loginData.Password, loginData.RememberMe, false);

            if (!result.Succeeded)
            {
                ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                return(View());
            }

            return(RedirectToAction("Index", "Home"));
        }
示例#6
0
        public async Task <IActionResult> Login(LoginInModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, false);

            if (!result.Succeeded)
            {
                ModelState.AddModelError("001", "Invalid Login");
                return(View(model));
            }

            return(RedirectToAction("Index", "Home"));
        }
示例#7
0
        public async Task <ServiceResult <string> > Login(LoginInModel model)
        {
            ServiceResult <string> result = new ServiceResult <string>();

            Logger.Info(string.Format("model.QRCode:{0}", model.QRCode));

            return(await Task.Run(() =>
            {
                DateTime startDateTime = DateTime.Now;

                string token = string.Empty;
                int isOk = 0;
                int i = 0;
                while (true)
                {
                    //要保持长链接
                    i++;
                    isOk = new MerchantComponent().GetLoginData(model.QRCode, out token);
                    result.Data = token;
                    if (isOk != 0)
                    {
                        break;
                    }

                    TimeSpan ts = DateTime.Now - startDateTime;
                    if (ts.TotalSeconds >= 120)
                    {
                        isOk = -1;
                        break;
                    }

                    Thread.Sleep(2000);
                }
                if (isOk > 0)
                {
                    return Result_OK(token);
                }
                else
                {
                    return Result_Fail(isOk.ToString(), 10000, "获取token失败");
                }
            }));
        }
示例#8
0
 public LoginInModel <StudentClient.Models.Teacher> Login(string username, string password)
 {
     try
     {
         LoginInModel <StudentClient.Models.Teacher> loginIn = new LoginInModel <StudentClient.Models.Teacher>();
         mLog.Info("Start Login treaher client,username:[{0}],password:[{1}].", username, Md5.GetEncryptionValue(password));
         if (base.Search(d => d.Teacher_TeaId == username && !d.Teacher_IsDel).Count > 0)
         {
             List <StudentClient.Models.Teacher> tearchers = base.Search(d => d.Teacher_TeaId == username && !d.Teacher_IsDel).ToList();
             if (tearchers.Count > 1)
             {
                 mLog.Warn("There are more than one account user,username:[{0}].", username);
             }
             StudentClient.Models.Teacher tearcher = tearchers.First();
             mLog.Info("Find users,username:[{0}],password:[{1}],realname:[{2}].", tearcher.Teacher_TeaId, tearcher.Teacher_Password, tearcher.Teacher_Name);
             if (Md5.GetEncryptionValue(password).Equals(tearcher.Teacher_Password))
             {
                 mLog.Info("Login success.");
                 loginIn.IsLogin     = true;
                 loginIn.CurrentUser = tearcher;
             }
             else
             {
                 mLog.Info("Login failed, password error.");
                 loginIn.IsLogin = false;
             }
         }
         else
         {
             mLog.Info("Login failed, username error.");
             loginIn.IsLogin = false;
         }
         return(loginIn);
     }
     catch (Exception e)
     {
         mLog.Error("An error occurre when login tearcher client,error:{0}", e.ToString());
         throw;
     }
 }
示例#9
0
 public JsonResult LoginIn(string username, string password, string type)
 {
     if (type == "0")
     {
         Student student = new Student();
         LoginInModel <StudentClient.Models.Student> loginIn = student.Login(username, password);
         if (loginIn.IsLogin)
         {
             Session["user"] = loginIn.CurrentUser;
         }
         return(Json(loginIn));
     }
     else if (type == "1")
     {
         Tearcher tearcher = new Tearcher();
         LoginInModel <StudentClient.Models.Teacher> loginIn = tearcher.Login(username, password);
         if (loginIn.IsLogin)
         {
             Session["tea"] = loginIn.CurrentUser;
         }
         return(Json(loginIn));
     }
     return(null);
 }
示例#10
0
        public ActionResult Login()
        {
            var model = new LoginInModel();

            return(View(model));
        }
示例#11
0
 public LoginInViewModel()
 {
     ClickCommand = new Command(arg => ClickMethod());
     LoginIn      = new LoginInModel();
 }