Exemple #1
0
        public string GetToken(UserModal user)
        //public Object GetToken(string mobileno, string email, string password)
        {
            string email    = user.Email;
            string mobileno = user.mobileno;
            string key      = "my_secret_key_12345"; //Secret key which will be used later during validation
            var    issuer   = "http://mysite.com";   //normally this will be your site URL

            var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key));
            var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);

            //Create a List of Claims, Keep claims name short
            var permClaims = new List <Claim>();

            permClaims.Add(new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()));
            permClaims.Add(new Claim("valid", user.id.ToString()));
            permClaims.Add(new Claim("useremail", email));
            permClaims.Add(new Claim("userid", mobileno));
            permClaims.Add(new Claim("name", user.DisplayName));

            //Create Security Token object by giving required parameters
            var token = new JwtSecurityToken(issuer,
                                             issuer, //Audience
                                             permClaims,
                                             expires: DateTime.Now.AddDays(1),
                                             signingCredentials: credentials);
            var jwt_token = new JwtSecurityTokenHandler().WriteToken(token);

            return(jwt_token);
        }
Exemple #2
0
    public ActionResult CreateUser(UserModal user)
    {
        Result <UserCpf>        cpf        = UserCpf.Create(user.cpf);
        Result <UserPassword>   password   = UserPassword.Create(user.password);
        Result <UserCardNumber> cardNumber = UserCardNumber.Create(user.cardNumber);
        Result <UserCardDigits> cardDigits = UserCardDigits.Create(user.cardDigits);
        Result <UserCardDate>   cardDate   = UserCardDate.Create(user.cardDate);

        Result result = Result.Combine(cpf, password, cardDate, cardDigits, cardNumber);

        if (result.IsNotSuccess)
        {
            return(new BadRequestObjectResult(result.Error));
        }

        User newUser = new User(cpf.Value, cardDate.Value, cardDigits.Value, cardNumber.Value, password.Value);

        var createUserOperation = _userService.CreateUser(newUser);

        if (createUserOperation.IsNotSuccess)
        {
            return(new BadRequestObjectResult(createUserOperation.Error));
        }

        return(new OkResult());
    }
Exemple #3
0
        public async Task <IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = new ApplicationUser()
            {
                UserName = model.Email, Email = model.Email
            };

            //set the IsDeleted property to false
            user.IsDeleted = false;
            UserModal ouser = new UserModal();

            ouser.Id           = user.Id;
            ouser.Email        = user.Email;
            ouser.UserName     = user.UserName;
            ouser.PasswordHash = MyEncryption.Encrypt(model.Password);
            bool flag = false;

            try
            {
                flag = new MyUserManager().CreateUser(ouser); //await UserManager.CreateAsync(user, model.Password);
            }
            catch (Exception ex) { ModelState.AddModelError("", ex.Message); }
            if (!flag)
            {
                ModelState.AddModelError("", "Failed to create user");
                return(BadRequest(ModelState));
            }

            return(Ok());
        }
 public IHttpActionResult Login(string mobileno, string password)
 {
     //if user exists and is active
     //verify username and password
     //if found return success
     if (_helpers.UserHelper.IsUserExists(mobileno))
     {
         UserModal user = _helpers.UserHelper.LoginUserByIdPass(mobileno, password);
         if (user != null)
         {
             AuthController controller = new AuthController();
             return(Ok(new {
                 userid = user.id,
                 mobileno = user.mobileno,
                 city = user.City,
                 token = controller.GetToken(user)
             }));
         }
         else
         {
             return(Unauthorized());
         }
     }
     else
     {
         return(BadRequest("Invalid User Id or Password"));
     }
 }
Exemple #5
0
        internal int GetTotalPontBalance(string mobileno)
        {
            UserModal user        = GetUserByMobileNo(mobileno);
            int?      totalpoints = _db.TblPoints.Where(t => t.UserId == _db.TblUsers.Where(x => x.MobileNo == mobileno).FirstOrDefault().Id).Sum(t => t.Points);

            return(totalpoints.HasValue ? totalpoints.Value : 0);
        }
    public override Task OnConnected()
    {
        var       newUsers = OnlineUser.userObj.Where(item => item.newStatus == true).Select(item => item.userId).ToList();
        UserModal user     = OnlineUser.userObj.Where(item => item.sessionId == HttpContext.Current.Request.Cookies["ASP.NET_SessionId"].Value.ToString()).SingleOrDefault();

        user.connectionId = Context.ConnectionId;
        return(Clients.All.joined(Context.ConnectionId, newUsers));
    }
Exemple #7
0
        public ActionResult Register(UserModal um)
        {
            var mongoClient = new MongoClient("Server=localhost:27017");
            var mongoServer = mongoClient.GetServer();
            var db          = mongoServer.GetDatabase("ficsDb");
            MongoCollection <BsonDocument> userDetails = db.GetCollection <BsonDocument>("inspects");

            userDetails.Insert(um);
            return(View());
        }
Exemple #8
0
        public async Task <IActionResult> Index()
        {
            Mcustomer user        = new Mcustomer();
            string    cookieValue = Request.Cookies["ChatUser"];

            if (cookieValue != null)
            {
                UserModal obj = JsonConvert.DeserializeObject <UserModal>(cookieValue);
                user = await new UserHandler().Authenticate(obj.CustomerCode, obj.Password);
            }
            return(View(user));
        }
        public ActionResult Login(UserModal userModel, string ReturnUrl)
        {
            if (!ModelState.IsValid)
            {
                this.ShowErrorMessage(Constant.DefaultErrorMessage);
                return(View());
            }

            var user = dbEntity.Users.SingleOrDefault(x => x.UserName == userModel.UserName);

            if (user == null)
            {
                this.ShowErrorMessage("Incorrect username or passsword");
                return(View());
            }

            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.UserName, DateTime.Now, DateTime.Now.AddDays(7), userModel.RememberMe, user.UserName);
            string     hashCookies           = FormsAuthentication.Encrypt(ticket);
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashCookies);

            Response.Cookies.Add(cookie);

            user.LastLogin = DateTime.Now;
            dbEntity.SaveChanges();

            HttpCookie myCookie = new HttpCookie("FarmCookies");

            //Add key-values in the cookie
            myCookie.Values.Add("UserId", user.Id.ToString());
            myCookie.Values.Add("Role", user.RoleId.ToString());
            myCookie.Values.Add("IsAdmin", user.IsAdmin.ToString());

            //set cookie expiry date-time. Made it to last for next 12 hours.
            myCookie.Expires = DateTime.Now.AddDays(1);
            Response.Cookies.Add(myCookie);

            LoggedInUser.Name    = user.Name;
            LoggedInUser.UserId  = user.Id;
            LoggedInUser.IsAdmin = user.IsAdmin;
            LoggedInUser.RoleId  = user.RoleId;

            var baseController = new BaseController();

            baseController.GetFormSetting();

            if (!string.IsNullOrEmpty(ReturnUrl))
            {
                return(Redirect(ReturnUrl));
            }

            return(RedirectToAction("Dashboard", "Home"));
        }
Exemple #10
0
        public async Task <IActionResult> Index()
        {
            UserModal user = HttpContext.Session.GetObject <UserModal>(WebUtil.User);

            if (user == null || user.Role != WebUtil.Admin)
            {
                return(RedirectToAction("Index", "LogIn"));
            }
            else
            {
                return(View(user));
            }
        }
Exemple #11
0
        internal int AddPoint(string mobileno, string description, int points)
        {
            UserModal user     = GetUserByMobileNo(mobileno);
            TblPoint  tblPoint = new TblPoint()
            {
                TransactionDate = DateTime.UtcNow,
                UserId          = _db.TblUsers.Where(x => x.MobileNo == mobileno).FirstOrDefault().Id,
                Description     = description,
                Points          = points
            };

            _db.TblPoints.Add(tblPoint);
            _db.SaveChanges();
            return(tblPoint.Id);
        }
Exemple #12
0
 public IHttpActionResult UserProfile()
 {
     if (ExtractToken(User))
     {
         //if user exists and is active
         //verify username and password
         //if found return success
         if (_helpers.UserHelper.IsUserExists(_auth.userid))
         {
             UserModal userentity = _helpers.UserHelper.GetUserProfile(_auth.userid);
             return(Ok(userentity));
         }
     }
     return(Unauthorized());
 }
Exemple #13
0
        internal bool UpdateUserProfile(UserModal userModal)
        {
            TblUser tblUser = _db.TblUsers.Where(t => t.MobileNo == userModal.mobileno).FirstOrDefault();

            if (tblUser != null)
            {
                tblUser.Email = userModal.Email;
                _db.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #14
0
        internal UserModal GetUserByMobileNo(string mobileno)
        {
            TblUser tblUser = _db.TblUsers.Where(t => t.MobileNo == mobileno).FirstOrDefault();

            if (tblUser != null)
            {
                UserModal userModal = new UserModal();
                userModal.mobileno         = tblUser.MobileNo;
                userModal.ReferredByMobile = tblUser.ReferredByMobile;
                userModal.ReferralCode     = tblUser.ReferralCode;
                return(userModal);
            }
            else
            {
                return(null);
            }
        }
Exemple #15
0
        internal List <PointTransactionModal> GetTopNPointTransaction(string mobileno, int topCount)
        {
            UserModal       user   = GetUserByMobileNo(mobileno);
            List <TblPoint> points = _db.TblPoints.OrderByDescending(t => t.TransactionDate)
                                     .Where(t => t.UserId == _db.TblUsers.Where(x => x.MobileNo == mobileno).FirstOrDefault().Id)
                                     .Take(topCount)
                                     .ToList();

            List <PointTransactionModal> pointTransactions = points.Select(t => new PointTransactionModal()
            {
                TransactionDate = t.TransactionDate,
                Description     = t.Description,
                Points          = t.Points
            }).ToList();

            return(pointTransactions);
        }
Exemple #16
0
        internal UserModal GetUserByIdPass(string mobileno, string password)
        {
            TblUser tblUser = _db.TblUsers.Where(t => t.MobileNo == mobileno && t.Password == password).FirstOrDefault();

            if (tblUser != null)
            {
                UserModal userModal = new UserModal();
                userModal.mobileno         = tblUser.MobileNo;
                userModal.ReferredByMobile = tblUser.ReferredByMobile;
                userModal.DisplayName      = tblUser.Name;
                userModal.Email            = tblUser.Email;
                userModal.City             = tblUser.City;
                return(userModal);
            }
            else
            {
                return(null);
            }
        }
Exemple #17
0
 public async Task <IActionResult> LogOut()
 {
     try
     {
         UserModal user = HttpContext.Session.GetObject <UserModal>(WebUtil.User);
         if (user != null)
         {
             await new UserHandler().OfflineUser(user.Id);
         }
         HttpContext.Session.Clear();
         result = "success";
     }
     catch (Exception ex)
     {
         result = ex.ToString();
         throw;
     }
     return(Json(result));
 }
        public ActionResult Register(UserModal um)
        {
            var mongoClient = new MongoClient("Server=localhost:27017");
            var mongoServer = mongoClient.GetServer();
            var db          = mongoServer.GetDatabase("ficsDb");
            MongoCollection <BsonDocument> userDetails  = db.GetCollection <BsonDocument>("users");
            MongoCollection <BsonDocument> cmpnyDetails = db.GetCollection <BsonDocument>("cmpdets");
            var document = new BsonDocument
            {
                { "companyName", "" },
                { "address", "" },
                { "licno", "" },
                { "user", um.userName },
                { "email", um.email }
            };

            userDetails.Insert(um);
            cmpnyDetails.Insert(document);
            return(View());
        }
Exemple #19
0
 public IHttpActionResult VerifyOTP(string mobileno, string otp, string password)
 {
     //if User exists and is InActiveUserWithCode
     //Validate OTP
     //Update user to Active
     if (_helpers.UserHelper.IsInActiveUserExists(mobileno))
     {
         if (_helpers.UserHelper.VerifyOTP(mobileno, otp))
         {
             _helpers.UserHelper.ActivateUser(mobileno, password);
             UserModal user = _helpers.UserHelper.GetUserProfile(mobileno);
             _helpers.PointHelper.AddPoint(mobileno, "Registration", 100);
             if (user.ReferredByMobile.Length > 0)
             {
                 _helpers.PointHelper.AddPoint(user.ReferredByMobile, "Referral Points for " + mobileno, 5);
             }
         }
     }
     return(Ok());
 }
        public bool Register(string email, string userName, string password)
        {
            bool userExists = _uow.UserRepository.UserExists(userName);

            if (!userExists)
            {
                UserModal newUser = new UserModal()
                {
                    Email    = email,
                    UserName = userName,
                    Password = BCrypt.Net.BCrypt.HashPassword(password)
                };

                _uow.UserRepository.Create(newUser);
                _uow.Commit();

                return(true);
            }
            return(false);
        }
        public ActionResult Register(UserModal um)
        {
            var mongoClient = new MongoClient("Server=localhost:27017");
            var mongoServer = mongoClient.GetServer();
            var db          = mongoServer.GetDatabase("hntsprt");
            MongoCollection <BsonDocument> userDetails    = db.GetCollection <BsonDocument>("users");
            MongoCollection <BsonDocument> ProfileDetails = db.GetCollection <BsonDocument>("profiledets");
            MongoCollection <BsonDocument> memdets        = db.GetCollection <BsonDocument>("memdets");
            profileModal pr = new profileModal();
            memModal     tm = new memModal();

            pr.userName = um.userName;
            pr.email    = um.email;
            tm.userName = um.userName;
            tm.email    = um.email;
            userDetails.Insert(um);
            ProfileDetails.Insert(pr);
            memdets.Insert(tm);
            return(View());
        }
Exemple #22
0
 public IHttpActionResult UpdateUserProfile()
 {
     //if user exists and is active
     //verify username and password
     //if found return success
     if (ExtractToken(User))
     {
         if (_helpers.UserHelper.IsUserExists(_auth.userid))
         {
             UserModal userModal = _helpers.UserHelper.GetUserProfile(_auth.userid);
             _helpers.UserHelper.UpdateUserProfile(userModal);
             return(Ok(true));
         }
         else
         {
             return(BadRequest("User Not Found"));
         }
     }
     return(Unauthorized());
 }
Exemple #23
0
        public async Task <IActionResult> LogIn(string email, string Password, bool RememberMe)
        {
            string result = string.Empty;

            try
            {
                Mcustomer user = await new UserHandler().Authenticate(email, Password);
                if (user != null)
                {
                    UserModal model = new UserModal();
                    model.Id           = user.Id;
                    model.CustomerCode = user.CustomerCode;
                    model.FirstName    = user.FirstName;
                    model.LastName     = user.LastName;
                    model.Password     = user.Password;
                    model.Role         = 1;
                    HttpContext.Session.SetObject(WebUtil.User, model);
                    //new code
                    if (RememberMe == true)
                    {
                        CookieOptions option = new CookieOptions();
                        option.Expires = DateTime.Now.AddDays(3);
                        string value = JsonConvert.SerializeObject(user);
                        Response.Cookies.Append("ChatUser", value, option);
                    }
                }
                else
                {
                    result = "Invalid Email or Password";
                }
            }
            catch (Exception ex)
            {
                result = ex.Message;
                Response.StatusCode = 404;
            }
            return(Json(result));
        }
        public UserModal Login(string userName, string password)
        {
            var userData = _uow.UserRepository.GetUserWithRoles(userName);

            if (userData == null)
            {
                return(null);
            }

            bool hashStatus = BCrypt.Net.BCrypt.Verify(password, userData.Password);

            if (hashStatus)
            {
                UserModal user = new UserModal()
                {
                    id       = userData.id,
                    UserName = userData.UserName,
                    Email    = userData.Email,
                    Roles    = userData.Roles
                };
                return(user);
            }
            return(null);
        }
Exemple #25
0
 public async Task <IActionResult> GetAllUsers()
 {
     try
     {
         UserModal user = HttpContext.Session.GetObject <UserModal>(WebUtil.User);
         if (user == null || user.Role != WebUtil.Admin)
         {
             return(RedirectToAction("Index", "LogIn"));
         }
         else
         {
             using (Context db = new Context())
             {
                 List <Mcustomer> customers = db.Mcustomers.ToList();
                 return(Json(customers));
             }
         }
     }
     catch (Exception ex)
     {
         string error = ex.ToString();
         throw;
     }
 }
 public RegisterView()
 {
     _user = new UserModal();
     InitializeComponent();
 }
 public LoginView()
 {
     _user = new UserModal();
     InitializeComponent();
 }
Exemple #28
0
 internal bool UpdateUserProfile(UserModal userModal)
 {
     return(_db.UpdateUserProfile(userModal));
 }
Exemple #29
0
        internal UserModal GetUserProfile(string mobileno)
        {
            UserModal user = _db.GetUserByMobileNo(mobileno);

            return(user);
        }
Exemple #30
0
        public UserModal LoginUserByIdPass(string mobileno, string password)
        {
            UserModal user = _db.GetUserByIdPass(mobileno, password);

            return(user);
        }