コード例 #1
0
ファイル: LoginController.cs プロジェクト: saney666/webCMS
        public JsonResult JsonMobileLogin(string username, string pwd)
        {
            bool   IsSuccess = false;
            string Msg       = "失敗…";

            try
            {
                if (LoginModel.Login(username.Trim(), pwd.Trim()))
                {
                    using (tsmc14BDataContext db = new tsmc14BDataContext())
                    {
                        var login = (from row in db.MobileLogin where row.login_name == username select row).FirstOrDefault();

                        if (login != null)
                        {
                            login.login_Time = DateTime.Now;

                            db.SubmitChanges();
                        }
                        else
                        {
                            MobileLogin ML = new MobileLogin();
                            ML.login_name = username;
                            ML.login_Time = DateTime.Now;

                            db.MobileLogin.InsertOnSubmit(ML);
                            db.SubmitChanges();
                        }

                        FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
                                                                                         username,//你想要存放在 User.Identy.Name 的值,通常是使用者帳號
                                                                                         DateTime.Now,
                                                                                         DateTime.Now.AddMinutes(30),
                                                                                         false, //將管理者登入的 Cookie 設定成 Session Cookie
                                                                                         "",    //userdata看你想存放啥
                                                                                         FormsAuthentication.FormsCookiePath);

                        string encTicket = FormsAuthentication.Encrypt(ticket);

                        Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));

                        IsSuccess = true;
                        Msg       = "登入成功";
                    }
                }
                else
                {
                    IsSuccess = false;
                    Msg       = "登入失敗";
                }
            }
            catch (Exception ex)
            {
                IsSuccess = false;
                Msg       = ex.Message;
            }

            return(Json(new { IsSuccess = IsSuccess, Msg = Msg }, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        protected async void OnClickAsync()
        {
            TextView    email    = FindViewById <TextView>(Resource.Id.Email);
            TextView    password = FindViewById <TextView>(Resource.Id.Password);
            MobileLogin ml       = await DbConnection.FetchLoginAsync(email.Text, password.Text);

            if (ml.UserAndPasswordCorrect == true)
            {
                Login l = new Login
                {
                    Name     = email.Text,
                    Password = password.Text,
                    Typ      = ml.UserType
                };
                LDbConnection.InsertLogin(l);
                if (ml.UserType == "User")
                {
                    LDbConnection.InsertUser(this, await DbConnection.FetchUserAsync(email.Text));
                    LDbConnection.InsertUserExpos(await DbConnection.FetchUserExposAsync(LDbConnection.GetUser()));
                    //LDbConnection.InsertHistory(await DbConnection.FetchHistory(LDbConnection.GetUser()));
                }
                if (ml.UserType == "Company")
                {
                    LDbConnection.InsertCompany(this, await DbConnection.FetchCompanyAsync(email.Text));
                    LDbConnection.InsertUserExpos(await DbConnection.FetchUserExposAsync(LDbConnection.GetCompany()));
                    //LDbConnection.InsertHistory(await DbConnection.FetchHistory(LDbConnection.GetCompany()));
                }
                var NxtAct = new Intent(this, typeof(StartActivity));
                StartActivity(NxtAct);
                Finish();
            }
            else
            {
                if (TextUtils.IsEmpty(email.Text) || TextUtils.IsEmpty(password.Text))
                {
                    if (TextUtils.IsEmpty(email.Text))
                    {
                        email.RequestFocus();
                        email.SetError("Pole nie może być puste!", null);
                    }
                    if (TextUtils.IsEmpty(password.Text))
                    {
                        password.RequestFocus();
                        password.SetError("Pole nie może być puste!", null);
                    }
                }
                else if (ml.UserAndPasswordCorrect == false)
                {
                    email.RequestFocus();
                    email.SetError("Zły Email lub Hasło!", null);
                    password.RequestFocus();
                    password.SetError("Zły Email lub Hasło!", null);
                }
                return;
            }
        }
コード例 #3
0
        // GET: Json
        public async System.Threading.Tasks.Task <JsonResult> Login(String email, String password)
        {
            bool   tempbool = false;
            string temptype = "";
            var    result   = await HttpContext.GetOwinContext().Get <ApplicationSignInManager>().PasswordSignInAsync(email, password, false, false);

            switch (result)
            {
            case SignInStatus.Success:
                ExpoesContext db  = new ExpoesContext();
                bool          exC = db.Companies.Any(p => p.Email == email);
                bool          exU = db.Users.Any(p => p.Email == email);
                if (exC == true)
                {
                    tempbool = true;
                    temptype = "Company";
                }
                else if (exU == true)
                {
                    tempbool = true;
                    temptype = "User";
                }
                break;

            case SignInStatus.LockedOut:
                tempbool = false;
                temptype = "";
                break;

            case SignInStatus.RequiresVerification:
                tempbool = false;
                temptype = "";
                break;

            case SignInStatus.Failure:
            default:
                tempbool = false;
                temptype = "";
                break;
            }
            MobileLogin l = new MobileLogin
            {
                UserAndPasswordCorrect = tempbool,
                UserType = temptype
            };

            return(Json(l, JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
        public void iOSMobileClickLoginButton()
        {
            MobileLogin.Click();

            System.Threading.Thread.Sleep(10000);
        }
 public User CheckLoginMobile(MobileLogin login)
 {
     return(_dBtsics.User
            .FirstOrDefault(q => q.Username.Equals(login.Xupj) && q.MobilePassword.Equals(login.Password)));
 }
コード例 #6
0
        // POST: api/MobileLogin
        public IHttpActionResult Post(MobileLogin plainTextLoginData)
        {
            if (!Common.GetAuthorization(Request))
            {
                return(Ok(new { Code = 401, Message = "Unauthorization" }));
            }
            using (TsicsContext db = new TsicsContext())
            {
                db.Database.ExecuteSqlCommand("delete from UserDevices where PlayerId = '' or PlayerId = null");
            }
            //Check User Login
            UserBusinessService userBs = Factory.Create <UserBusinessService>("User", ClassType.clsTypeBusinessService);

            MobileLogin loginData = new MobileLogin
            {
                Xupj = plainTextLoginData.Xupj, Password = Common.Base64Encode(plainTextLoginData.Password)
            };
            User userM = userBs.CheckLoginMobile(loginData);

            if (userM != null)
            {
                var usrd = new UserDevices {
                    UserId = userM.UserId, PlayerId = plainTextLoginData.PlayerId
                };
                userM.MobileToken = Common.AccessToken() + userM.UserId;
                userM.PlayerId    = plainTextLoginData.PlayerId;
                userBs.Edit(userM);

                if (usrd.PlayerId != null)
                {
                    userBs.InsertData(usrd);
                }
                if (!string.IsNullOrWhiteSpace(userM.PhotoProfile))
                {
                    userM.PhotoProfile = WebConfigure.GetDomain() + "/Upload/UserProfile/" + userM.PhotoProfile;
                }
                else
                {
                    userM.PhotoProfile = WebConfigure.GetDomain() + "/assets/images/repository/avatar-default.jpg";
                }

                UserAPI userData = new UserAPI()
                {
                    UserId          = userM.UserId,
                    Name            = userM.Name,
                    EmployeeId      = userM.EmployeeId,
                    AreaName        = string.IsNullOrWhiteSpace(userM.AreaName) ? "HEAD OFFICE" : userM.AreaName,
                    BranchName      = string.IsNullOrWhiteSpace(userM.BranchName) ? "" : userM.BranchName,
                    CreatedAt       = userM.CreatedAt,
                    AreaCode        = userM.AreaCode,
                    BranchCode      = userM.BranchCode,
                    MasterAreaId    = userM.MasterAreaId,
                    MasterBranchId  = userM.MasterBranchId,
                    Email           = userM.Email,
                    RoleId          = userM.RoleId,
                    RoleDescription = userM.RoleDescription,
                    RoleName        = userM.RoleId == 0 || _UserRoleBusinessService.GetDetail(userM.RoleId) == null ? "GUEST" : _UserRoleBusinessService.GetDetail(userM.RoleId).Name,
                    Dob             = userM.Dob,
                    IsDelegate      = userM.IsDelegate,
                    MobileToken     = userM.MobileToken,
                    PhotoProfile    = userM.PhotoProfile,
                    POH_Name        = userM.POH_Name,
                    Status          = userM.Status,
                    MobilePassword  = userM.MobilePassword,
                    Position        = userM.Position,
                    Phone           = userM.Phone,
                    PlayerId        = userM.PlayerId,
                    Username        = userM.Username,
                    TechnicalJobExperienceDuration = userM.TechnicalJobExperienceDuration,
                    TechnicalJobTitle = userM.TechnicalJobTitle,
                };
                Delegation userD = userBs.GetDetailDelegationByUserFrom(userM.UserId);
                if (userD != null)
                {
                    DelegationAPI delegationAPI = new DelegationAPI()
                    {
                        DelegateId = userD.DelegateId,
                        StartDate  = userD.StartDate.Value.ToString("dddd, dd MMMM yyyy"),
                        EndDate    = userD.EndDate.Value.ToString("dddd, dd MMMM yyyy"),
                        ToUser     = userBs.GetDetail(userD.ToUser),
                        Status     = userD.Status,
                        CreatedAt  = userD.CreatedAt.Value.ToString("dddd, dd MMMM yyyy")
                    };
                    return(Ok(new { Code = 200, Authorization = "true", Data = userData, delegation = delegationAPI }));
                }
                else
                {
                    DelegationAPI delegationAPI = new DelegationAPI()
                    {
                        DelegateId = 0,
                        StartDate  = null,
                        EndDate    = null,
                        FromUser   = null,
                        ToUser     = null,
                        Status     = 0,
                        CreatedAt  = null
                    };
                    return(Ok(new { Code = 200, Authorization = "true", Data = userData, delegation = delegationAPI }));
                }
            }
            else
            {
                return(Ok(new { Code = 401, Authorization = "false", Message = "Gagal Login" }));
            }
        }