示例#1
0
        //[ThreadStatic]
        //private static User CurraaentUser;
        #endregion

        #region Login
        public static string GetLoginData(LoginDataCriteria LoginData)
        {
            //  IEnumerable<string> ReturnString=new string[]{};


            using (UsersContext Context = new UsersContext())
            {

                var text = "amer";
                string DcriptedPassword = LoginData. Password;
                if (LoginData.IsEncrypted)
                    DcriptedPassword = UserService.DecryptText(LoginData.Password, text);
                User CurrentUser;
                if (LoginData.IsAccout)
                  CurrentUser = GetCurrentUser(LoginData.Email, DcriptedPassword);
                else
                    CurrentUser = GetCurrentUser(LoginData.Email);


                // check if the login with username and password match
                if (CurrentUser == null) return "Login Faild";

                var CurrentAccount = (from Acc in Context.Accounts
                                      where Acc.UserID == CurrentUser.UserID
                                      select Acc).FirstOrDefault();
                var DTO = new UserLoginDTO()
                {
                    FirstName = CurrentAccount.FirstName != null ? CurrentAccount.FirstName : ""
                    ,
                    MiddelName = CurrentAccount.MiddelName != null ? CurrentAccount.MiddelName : ""
                    ,
                    LastName = CurrentAccount.LastName != null ? CurrentAccount.LastName : "",
                    Gender = CurrentAccount.Gender.HasValue ? CurrentAccount.Gender.Value.ToString() : ""
                    ,
                    Email = CurrentUser.Email,
                    Password = CurrentUser.Password != null ? CurrentUser.Password : "",
                    CreatedOnDate = CurrentUser.CreatedOnDate.ToString("dd/MM/yyyy"),
                    BirthDay = CurrentAccount.BirthDay.HasValue ? CurrentAccount.BirthDay.Value.ToString("dd/MM/yyyy") : "",
                    UserID = CurrentUser.UserID,
                    AccountID = CurrentAccount.AccountID,
                    BadgeID = CurrentAccount.BadgeID != null ? CurrentAccount.BadgeID : 0,
                    CountryID = CurrentAccount.CountryID != null ? CurrentAccount.CountryID : "",
                    ModefiedOnDate = CurrentAccount.ModefiedOnDate.HasValue ? CurrentAccount.ModefiedOnDate.Value.ToString("dd/MM/yyyy") : ""
                    ,
                    IsAutoLogin = LoginData.HeaderIsAutoLogin != null ? LoginData.HeaderIsAutoLogin.ToString() : ""
                   ,
                    Points = CurrentAccount.Points.HasValue ? CurrentAccount.Points.Value : 0
                };
                return JsonConvert.SerializeObject(DTO);
            }
 

        }
示例#2
0
        public IActionResult UserLogin(string UserEmail ,string Password,string DeviceToken)
        {
            try
            {
                if (Request.Headers["UserEmail"] != null)
                    UserEmail = Request.Headers["UserEmail"];
                if (Request.Headers["Password"] != null)
                    Password = Request.Headers["Password"];
                if (Request.Headers["DToken"] != null)
                    DeviceToken = Request.Headers["DToken"];

                var IsAccount = Request.Headers["IsAccount"];// 0=social network
                var headerIsAutoLogin = Request.Headers["IsAutoLogin"];
                if (headerIsAutoLogin == null)
                    headerIsAutoLogin = "";
                //  var DecKey = Request.Headers["Key"];

                LoginDataCriteria LoginData = new LoginDataCriteria() {
                    IsAccout =Boolean.Parse( IsAccount), HeaderIsAutoLogin = headerIsAutoLogin, Password = Password, Email = UserEmail, DeviceToken = DeviceToken };
                
                //Decryption Block........
               //   UserEmail = UserService.DecryptText(UserEmail, DecKey);
               // Password = UserService.DecryptText(Password, DecKey);
               
                var DataResult = UserService.UserLogin(LoginData);

                return new ObjectResult(DataResult);

            }
            catch(Exception Ed)
            {
                return new ObjectResult(Ed.Message);
            }


        }
示例#3
0
        public static string SaveNewUser(string UserEmail, string Password, string DeviceToken)
        {
            try
            {
                using (var context = new UsersContext())
                {
                    // add new User 
                    var NewUser = context.Users.Add(new User() { Email = UserEmail, Password = Password, CreatedOnDate = DateTime.Now });
                    context.SaveChanges();
                    //then add new account 
                    var NewAccount = context.Accounts.Add(new Account() { UserID = NewUser.Entity.UserID, CreatedOnDate = DateTime.Now, ModefiedOnDate = null });
                    context.SaveChanges();
                    //finally add new device token .......
                    var newToken = context.Tokens.Add(new DeviceTokenEntity() { DeviceToken = DeviceToken, DidChangeToday = false, IsActive = true, AccountID = NewAccount.Entity.AccountID });
                    context.SaveChanges();
                    LoginDataCriteria LoginData = new LoginDataCriteria() { Email = UserEmail, Password = Password, HeaderIsAutoLogin = null, IsEncrypted = false };
                    if (Password == null) LoginData.IsAccout = false;
                    return UserService.GetLoginData(LoginData);
                }
            }
            catch (Exception ex)
            {
                return ex.Message;
            }

        }
示例#4
0
        public static string UserLogin(LoginDataCriteria LoginData)
        {
            try
            {
              

                DeviceTokenEntity CurrentDeviceTocken = new DeviceTokenEntity() { DeviceToken = LoginData.DeviceToken };
                CheckTokenResult CheckTokenResult = CheckTokenResult.None;
                if ( LoginData.IsAccout)
                    CheckTokenResult = UserService.CheckTokenForLogin(CurrentDeviceTocken, LoginData.Email, LoginData.Password);
                else
                    CheckTokenResult = UserService.CheckTokenForSocialMediaLogin(CurrentDeviceTocken, LoginData.Email);
                if ( CheckTokenResult== CheckTokenResult.OK)
                {
                    LoginData.IsEncrypted = false;
                    string Data = UserService.GetLoginData(LoginData);

                    return Data;

                }
                else
                {
                    if (CheckTokenResult == CheckTokenResult.Register)
                        return UserService.SaveNewUser(LoginData.Email, null, LoginData.DeviceToken);
                    else

                        return CheckTokenResult.ToString();
                }
            }
            catch (Exception ex)
            {
                //error in the code
                return ex.Message;
            }
        }