public ActionResult Login(UserLogin ul)
        {
            UserDetailsBEL objUserBEL = new UserDetailsBEL();



            if (ModelState.IsValid)
            {
                if (ul.UserName.Contains('@'))
                {
                    objUserBEL.Email_Id = ul.UserName;
                }
                else
                {
                    objUserBEL.Phone_No1 = ul.UserName;
                }
                objUserBEL.Password = Secure.Encrypt(ul.Password);


                UserDetailsDAL objUserDAL = new UserDetailsDAL();
                //UserDetailsBEL tr =
                UserLoginDetailsViewModel vm = new UserLoginDetailsViewModel(objUserDAL.FunAuthenticateUser(objUserBEL));
                //UserLoginDetailsViewModel vm = new UserLoginDetailsViewModel(objUserDAL.CheckPhoneNoExists(objUserBEL.Phone_No1));
                if (vm.ErrorMessage == string.Empty)
                {
                    FormsAuthentication.SetAuthCookie(objUserBEL.User_ID, true);
                    Session["userDetail"]        = vm;
                    Session["userPhoneNo/Email"] = !string.IsNullOrWhiteSpace(vm.Phone_No1)? vm.Phone_No1: vm.Email_Id;

                    string tempdata;
                    if (TempData["RequestedUrl"] != null)
                    {
                        tempdata = Convert.ToString(TempData["RequestedUrl"]);
                        TempData["RequestedUrl"] = null;
                        //need to modify later
                        return(Redirect("http://localhost/" + tempdata));
                        // return  RedirectToAction(tempdata, "parkingArea");
                    }
                    else
                    {
                        return(RedirectToAction("Index", "UserDashbaord"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", vm.ErrorMessage.ToString());
                }
            }
            else
            {
                ModelState.AddModelError("", "Login data is incorrect!");
            }
            return(View());
        }
        public ActionResult SignUp(SignupViewModel vm)
        {
            UserDetailsBEL objUserBEL = new UserDetailsBEL();

            objUserBEL.Email_Id   = vm.EmailId;
            objUserBEL.Password   = Secure.Encrypt(vm.Password);
            objUserBEL.First_Name = vm.FirstName;
            objUserBEL.Last_Name  = vm.LastName;
            objUserBEL.Phone_No1  = vm.Mobile;

            UserDetailsDAL objUserDAL = new UserDetailsDAL();
            List <string>  OTPList    = new List <string>();

            if (ModelState.IsValid)
            {
                UserLoginDetailsViewModel LDvm = new UserLoginDetailsViewModel(objUserDAL.AddUserDetails(objUserBEL));
                if (string.IsNullOrEmpty(LDvm.ErrorMessage) && (LDvm.User_ID != "" || LDvm.User_ID != string.Empty))
                {
                    //FormsAuthentication.SetAuthCookie(objUserBEL.User_ID, true);
                    Session["userDetail"] = LDvm;
                    // return RedirectToAction("Index", "UserDashbaord");
                    OTPBEL OTPBel = new OTPBEL();
                    OTPList = OTPBel.GetAndSendOTP(Convert.ToInt64(objUserBEL.Phone_No1));
                    if (OTPList != null)
                    {
                        if (Convert.ToBoolean(OTPList[2]))
                        {
                            // Session[OTPList[2]+"_OTP"] = OTPList[0];
                            Session["OTP"] = OTPList[0];
                        }
                    }

                    return(RedirectToAction("VerifyOTP", "OTP"));
                    //  return RedirectToAction("Login", "TrueWheelsUser");
                }
                else
                {
                    ModelState.AddModelError("", LDvm.ErrorMessage.ToString());
                }
            }
            else
            {
                // Response.Write(ModelState.SelectMany(x => x.Value.Errors.Select(z => z.Exception)));
                ModelState.AddModelError("", "Data is incorrect!");
            }
            return(View());
        }
        public bool SignUpWithFB(string FirstName, string LastName, string EmailId, string Fb_id)
        {
            UserDetailsBEL objUserBEL = new UserDetailsBEL();

            objUserBEL.Email_Id       = EmailId;
            objUserBEL.Password       = FirstName + "@Truewheels";
            objUserBEL.First_Name     = FirstName;
            objUserBEL.Last_Name      = LastName;
            objUserBEL.SignUp_Mode_ID = "FB";
            objUserBEL.Phone_No1      = "NA";
            objUserBEL.Other_ID       = Fb_id;

            UserDetailsDAL            objUserDAL = new UserDetailsDAL();
            UserLoginDetailsViewModel LDvm       = new UserLoginDetailsViewModel(objUserDAL.AddUserDetails(objUserBEL));

            if (string.IsNullOrEmpty(objUserBEL.ErrorMessage) && (objUserBEL.User_ID != "" || objUserBEL.User_ID != string.Empty))
            {
                //FormsAuthentication.SetAuthCookie(objUserBEL.User_ID, true);
                Session["userDetail"] = LDvm;
                return(true);
                // return RedirectToAction("Index", "UserDashbaord");
            }
            else
            {
                return(false);

                ModelState.AddModelError("", objUserBEL.ErrorMessage.ToString());
            }

            //UserDetailsBEL tr = objUserDAL.AddUserDetails(objUserBEL);
            //if (tr.ErrorMessage == "")
            //{

            //    //FormsAuthentication.SetAuthCookie(objUserBEL.User_ID, true);
            //    return true;
            //    //return RedirectToAction("Index", "UserDashbaord");
            //}
            //else
            //{
            //    return false;
            //    ModelState.AddModelError("", tr.ErrorMessage.ToString());
            //}

            // return View();
        }
示例#4
0
        public HttpResponseMessage Signup(SignupViewModel vm)
        {
            var     res      = new HttpResponseMessage();
            JObject jContent = new JObject();
            Random  ran      = new Random();

            if (vm != null)
            {
                vm.Password        = Secure.Encrypt(vm.Password);// Secure.Encrypt("TWuser@" + Convert.ToString(ran.Next(1000, 9999)));
                vm.ConfirmPassword = Secure.Encrypt(vm.Password);
                if (ModelState.IsValid)
                {
                    try
                    {
                        UserDetailsBEL objUserBEL = new UserDetailsBEL();

                        objUserBEL.Email_Id   = vm.EmailId;
                        objUserBEL.Password   = vm.Password;
                        objUserBEL.First_Name = vm.FirstName;
                        objUserBEL.Last_Name  = vm.LastName;
                        objUserBEL.Phone_No1  = vm.Mobile;

                        UserDetailsDAL            objUserDAL = new UserDetailsDAL();
                        UserLoginDetailsViewModel ulvm       = new UserLoginDetailsViewModel(objUserDAL.AddUserDetails(objUserBEL));

                        if (ulvm.User_ID != "0")
                        {
                            res.StatusCode = HttpStatusCode.Created;
                            jContent       = new JObject(
                                new JProperty("result",
                                              new JObject(
                                                  new JProperty("Success", true),
                                                  new JProperty("Message", "User added successfully"),
                                                  new JProperty("Transation", ulvm.User_ID))));
                        }
                        else
                        {
                            res.StatusCode = HttpStatusCode.BadRequest;
                            jContent       = new JObject(
                                new JProperty("result",
                                              new JObject(
                                                  new JProperty("Success", false),
                                                  new JProperty("Message", ulvm.ErrorMessage),
                                                  new JProperty("ErrorMessage", ulvm.ErrorMessage),
                                                  new JProperty("Transation", ulvm.User_ID))));
                        }
                    }
                    catch (Exception ex)
                    {
                        res.StatusCode = HttpStatusCode.BadRequest;
                        jContent       = new JObject(
                            new JProperty("result",
                                          new JObject(
                                              new JProperty("Success", false),
                                              new JProperty("Message", ex.Message),
                                              new JProperty("ErrorMessage", ex.InnerException.ToString()),
                                              new JProperty("Transation", null))));
                    }
                }
                else
                {
                    var errorList = (from item in ModelState
                                     where item.Value.Errors.Any()
                                     select item.Value.Errors[0].ErrorMessage).ToList();
                    res.StatusCode = HttpStatusCode.BadRequest;
                    jContent       = new JObject(
                        new JProperty("result",
                                      new JObject(
                                          new JProperty("Success", false),
                                          new JProperty("Message", "Invalid Input"),
                                          new JProperty("ErrorMessage", errorList),
                                          new JProperty("Transation", null))));
                }
            }
            res.Content = new StringContent(jContent.ToString());
            return(res);
        }
示例#5
0
        public HttpResponseMessage IsRegistered(string Phone_no)
        {
            // string Phone_no = av.Mobile; //this.Request.Content.ReadAsStringAsync().Result;
            var     res = new HttpResponseMessage();
            JObject jContent;

            if (!string.IsNullOrEmpty(Phone_no))//(ModelState.IsValid)
            {
                try
                {
                    UserDetailsDAL            objUserDAL = new UserDetailsDAL();
                    UserLoginDetailsViewModel lvm        = new UserLoginDetailsViewModel(objUserDAL.CheckPhoneNoExists(Phone_no));

                    if (lvm.User_ID != "0")
                    {
                        res.StatusCode = HttpStatusCode.Accepted;
                        jContent       = new JObject(
                            new JProperty("result",
                                          new JObject(
                                              new JProperty("Success", true),
                                              new JProperty("Email", lvm.Email_Id),
                                              new JProperty("Mobile", lvm.Phone_No1),
                                              new JProperty("Username", lvm.User_Name),
                                              new JProperty("LastLogin", lvm.Last_Login),
                                              new JProperty("UserId", lvm.User_ID),
                                              new JProperty("Alternate_Email_Id", lvm.Alternate_Email_Id))));
                    }
                    else
                    {
                        res.StatusCode = HttpStatusCode.Unauthorized;
                        jContent       = new JObject(
                            new JProperty("result",
                                          new JObject(
                                              new JProperty("Success", false),
                                              new JProperty("Message", lvm.ErrorMessage),
                                              new JProperty("ErrorMessage", lvm.ErrorMessage),
                                              new JProperty("UserId", lvm.User_ID))));
                    }
                }
                catch (Exception ex)
                {
                    res.StatusCode = HttpStatusCode.BadRequest;
                    jContent       = new JObject(
                        new JProperty("result",
                                      new JObject(
                                          new JProperty("Success", false),
                                          new JProperty("Message", ex.Message),
                                          new JProperty("ErrorMessage", ex.InnerException.ToString()),
                                          new JProperty("UserId", null))));
                }

                //return Request.CreateResponse<string>(HttpStatusCode.OK, mystring);
            }
            else
            {
                res.StatusCode = HttpStatusCode.BadRequest;
                jContent       = new JObject(
                    new JProperty("result",
                                  new JObject(
                                      new JProperty("Success", false),
                                      new JProperty("Message", "Invalid Input"),
                                      new JProperty("ErrorMessage", "Phone_no Either null or Empty"),
                                      new JProperty("UserId", null))));
            }
            res.Content = new StringContent(jContent.ToString());
            return(res);
            //throw new HttpResponseException(HttpStatusCode.BadRequest);
        }
示例#6
0
        public HttpResponseMessage Login(UserLogin vm)
        {
            var     res = new HttpResponseMessage();
            JObject jContent;

            if (ModelState.IsValid)
            {
                try
                {
                    UserDetailsBEL objUserBEL = new UserDetailsBEL();

                    objUserBEL.Email_Id  = vm.Email;
                    objUserBEL.Password  = vm.Password;
                    objUserBEL.Phone_No1 = vm.Mobile;
                    objUserBEL.User_Name = vm.UserName;

                    UserDetailsDAL            objUserDAL = new UserDetailsDAL();
                    UserLoginDetailsViewModel lvm        = new UserLoginDetailsViewModel(objUserDAL.FunAuthenticateUser(objUserBEL));

                    if (lvm.User_ID != "0")
                    {
                        res.StatusCode = HttpStatusCode.Accepted;
                        jContent       = new JObject(
                            new JProperty("result",
                                          new JObject(
                                              new JProperty("Success", true),
                                              new JProperty("Email", lvm.Email_Id),
                                              new JProperty("Mobile", lvm.Phone_No1),
                                              new JProperty("Username", lvm.User_Name),
                                              new JProperty("LastLogin", lvm.Last_Login),
                                              new JProperty("UserId", lvm.User_ID))));
                    }
                    else
                    {
                        res.StatusCode = HttpStatusCode.Unauthorized;
                        jContent       = new JObject(
                            new JProperty("result",
                                          new JObject(
                                              new JProperty("Success", false),
                                              new JProperty("Message", lvm.ErrorMessage),
                                              new JProperty("ErrorMessage", lvm.ErrorMessage),
                                              new JProperty("UserId", lvm.User_ID))));
                    }
                }
                catch (Exception ex)
                {
                    res.StatusCode = HttpStatusCode.BadRequest;
                    jContent       = new JObject(
                        new JProperty("result",
                                      new JObject(
                                          new JProperty("Success", false),
                                          new JProperty("Message", ex.Message),
                                          new JProperty("ErrorMessage", ex.InnerException.ToString()),
                                          new JProperty("UserId", null))));
                }

                //return Request.CreateResponse<string>(HttpStatusCode.OK, mystring);
            }
            else
            {
                var errorList = (from item in ModelState
                                 where item.Value.Errors.Any()
                                 select item.Value.Errors[0].ErrorMessage).ToList();
                res.StatusCode = HttpStatusCode.BadRequest;
                jContent       = new JObject(
                    new JProperty("result",
                                  new JObject(
                                      new JProperty("Success", false),
                                      new JProperty("Message", "Invalid Input"),
                                      new JProperty("ErrorMessage", errorList),
                                      new JProperty("Transation", null))));
            }
            res.Content = new StringContent(jContent.ToString());
            return(res);
        }