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()); } }
public async Task <ActionResult> CreateUser(UserPartial iUser) { try { SignalRChatContext DB = new SignalRChatContext(); using (var transaction = DB.Database.BeginTransaction()) { try { bool isExist = UserFunctions.CheckIfUserExist(iUser, DB); if (isExist == true) { return(BadRequest()); } UserCls newUser = UserFunctions.CreateNewUser(iUser, DB); newUser.code = SignInCodesFucntions.GenerateCodeForUser(newUser.id, DB); transaction.Commit(); newUser.token = JwtHandler.CreateJwt(newUser.id, newUser.userName, DateTime.Now); await hubContext.Clients.All.AddUserEvent(newUser.id); return(new JsonResult(newUser)); } catch (Exception exc) { //write exc to log... transaction.Rollback(); return(BadRequest()); } } } catch (Exception ex) { //write ex to log... return(BadRequest()); } }
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)); }