Example #1
0
        public ActionResult ReceiveCode(loginCls iLoginObj) //since only one param [FromBody] needed
        {
            try
            {
                int newCode = SignInCodesFucntions.UpdateCodeForUserByPhone(iLoginObj.phone, null);

                //Code should be sent to mail/phone... if user not exist, Code text box should appear, but phone mail should not be sent. Irrelevant user should not know whether user exist or not.
                return(new JsonResult(newCode));
            }
            catch (Exception exc)
            {
                //write exc to log...
                return(BadRequest());
            }
        }
Example #2
0
        public async Task <ActionResult> LogIn(loginCls iLoginObj)
        {
            var userValidData = SignInCodesFucntions.ValidateCode(iLoginObj.phone, iLoginObj.code);

            if (userValidData == null)
            {
                return(BadRequest());
            }

            var token = JwtHandler.CreateJwt(userValidData.userId, userValidData.userName, DateTime.Now);

            UserCls res = UserFunctions.UserByPhoneAndCode(iLoginObj.phone, iLoginObj.code);

            res.token = token;
            res.id    = res.id; //id should not be returned. selected user should return dummy id or encrypted one.
            res.code  = null;

            await this.hubContext.Clients.All.AddUserEvent(res.id);

            return(new JsonResult(res));
        }