public LoginResponse Login(LoginRequest request)
        {
            request.mobile_number = Common.GetStandardMobileNumber(request.mobile_number);
            LoginResponse response     = new LoginResponse();
            Driver        driver       = null;
            string        hashPassword = TokenGenerator.GetHashedPassword(request.password, 49);

            try
            {
                using (DriverDao dao = new DriverDao())
                {
                    //driver = dao.FindByMobileNumber(request.mobile_number);
                    driver = dao.FindByMobileNumberAndPassword(request.mobile_number, hashPassword);

                    if (driver == null)
                    {
                        MakeNoDriverResponse(response);
                        return(response);
                    }

                    driver.AppID     = request.app_id;
                    driver.AppToken  = request.push_token;
                    driver.LastLogin = DateTime.Now;
                    driver.AccToken  = TokenGenerator.GenerateToken(driver.DriverName, driver.Password, driver.MobileNumber);
                    dao.Update(driver);
                    response.code             = 0;
                    response.user_login       = new UserLoginDto();
                    response.driver_details   = new DriverDetails();
                    response.reminder_details = new ReminderDetailsDto();

                    var reminder = dao.GetRemindersForDriver();
                    response.has_reminder = (reminder == null ? 0 : 1);
                    //if (reminder == null)
                    //{
                    //    reminder = new Reminder();
                    //}
                    DriverHelper.CopyFromEntity(response, driver, reminder);

                    response.has_resource = 1;
                    response.message      = MessagesSource.GetMessage("login.ok");
                    return(response);
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
            }

            return(response);
        }
Exemplo n.º 2
0
        //public static ResendOtpResponse ResendOtp(ResendOtpRequest request)
        //{
        //    ResendOtpResponse response = new ResendOtpResponse();
        //    response.otp_details = new OtpDetailsDto();
        //    AgentBoss agentBoss = null;
        //    try
        //    {
        //        using (AgentBossDao userDao = new AgentBossDao())
        //        {
        //            // agentBoss = GetAuthAgentBoss(request.user_id, request.auth_token, response);
        //            agentBoss = userDao.FindByMobileNumber(request.mobile_number);
        //        }
        //        if (agentBoss == null)
        //        {
        //            MakeNouserResponse(response);
        //            return response;
        //        }

        //        OTPServices.ResendOTP(agentBoss.AbosID, agentBoss.MobileNumber, "B");
        //        response.code = 0;
        //        response.has_resource = 1;
        //        response.message = MessagesSource.GetMessage("otp.resent");
        //        response.otp_details.send_otp = 1;
        //        return response;
        //    }
        //    catch (Exception ex)
        //    {
        //        response.MakeExceptionResponse(ex);
        //        return response;
        //    }
        //}

        public static ResponseDto ResetPassword(ResetPasswordRequest request)
        {
            request.mobile_number = Common.GetStandardMobileNumber(request.mobile_number);
            ResponseDto response            = new ResponseDto();
            AgentBoss   agentBoss           = null;
            string      newPasswordHash     = TokenGenerator.GetHashedPassword(request.new_password, 49);
            string      confirmPasswordHash = TokenGenerator.GetHashedPassword(request.confirm_password, 49);

            try
            {
                //if (!AgentBossServices.CheckAgentBoss(request.user_id, request.auth_token, response))
                //if (!AgentBossServices.CheckAgentBossNotAuthToken(request.user_id, response))
                //{
                //    return response;
                //}
                using (AgentBossDao dao = new AgentBossDao())
                {
                    agentBoss = dao.FindByMobileNumber(request.mobile_number);
                    //agentBoss = dao.FindById(request.user_id);
                    if (agentBoss == null)
                    {
                        MakeNouserResponse(response);
                        return(response);
                    }
                    if (newPasswordHash == confirmPasswordHash)
                    {
                        agentBoss.Password = TokenGenerator.GetHashedPassword(request.new_password, 49);
                        dao.Update(agentBoss);
                        response.code         = 0;
                        response.has_resource = 1;
                        response.message      = MessagesSource.GetMessage("passwd.reset");
                        return(response);
                    }
                }
                response.code         = 1;
                response.has_resource = 0;
                response.message      = MessagesSource.GetMessage("exception");
                return(response);
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
                return(response);
            }
        }
Exemplo n.º 3
0
        public static ResponseDto ChangePassword(ChangePasswordAgentBossRequest request)
        {
            ResponseDto response        = new ResponseDto();
            AgentBoss   agentBoss       = null;
            string      oldPasswordHash = TokenGenerator.GetHashedPassword(request.old_password, 49);

            try
            {
                if (!AgentBossServices.CheckAgentBoss(request.user_id, request.auth_token, response))
                {
                    MakeNouserResponse(response);
                    return(response);
                }
                using (AgentBossDao dao = new AgentBossDao())
                {
                    agentBoss = dao.FindById(request.user_id);
                    if (agentBoss.Password == oldPasswordHash)
                    {
                        agentBoss.Password = TokenGenerator.GetHashedPassword(request.new_password, 49);
                        dao.Update(agentBoss);
                        response.code         = 0;
                        response.has_resource = 1;
                        response.message      = MessagesSource.GetMessage("password.changed");
                        return(response);
                    }
                }
                response.code         = 1;
                response.has_resource = 0;
                response.message      = MessagesSource.GetMessage("exception");
                return(response);
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
                return(response);
            }
        }